You need to sign in to do that
Don't have an account?
Premanath
Date text field should Accept only dd/mm/yyyy
String RE_date= '(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)';
Pattern MyPattern = Pattern.compile(RE_date);
Matcher MyMatcher = MyPattern.matcher(myDate);
The above code is working
if we enter 5/6/1988 also it is Accepting... so i need it should accept only dd/mm/yyyy (05/06/1988)... other wise it should give error..
how can i achive this.
Date text field using Pattern
Date text field should Accept only dd/mm/yyyy
String RE_date= '(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)';
Pattern MyPattern = Pattern.compile(RE_date);
Matcher MyMatcher = MyPattern.matcher(myDate);
The above code is working
if we enter 5/6/1988 also it is Accepting... so i need it should accept only dd/mm/yyyy (05/06/1988)... other wise it should give error..
how can i achive this.
Use this following Regular Expression Details, This will support leap year also.
^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$
Matches
[29/02/2000], [30/04/2003], [01/01/2003]
Non-Matches
[29/02/2001], [30-04-2003], [1/1/1899]
Thanks for your reply.
when i Apply that above code i am getting Error.
Compile Error: Invalid string literal '^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$'. Illegal character sequence '\d' in string literal. at line 213 column 28
String RE_date= '(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)';
this String i am copying
Please how to insert above Code.
Thanks a lot,
^(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\/02\/(19|20)(([02468][048])|([13579][26]))))$
Tha expression that i share eleyer actully cover leep years also
from this site
http://www.regular-expressions.info/javascriptexample.html
and both are running fine