function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PremanathPremanath 

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.

SRKSRK
Hi

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]
PremanathPremanath
Hi,
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,

SRKSRK
You can try this expression in place of that 

^(((((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 

SRKSRK
i have write and test both the expression online

from this site
http://www.regular-expressions.info/javascriptexample.html

and both are running fine