Link to home
Start Free TrialLog in
Avatar of Varshini S
Varshini S

asked on

Regular Expression not working

i am using following regular expression validator, but it not working with the date 19-Feb-2013
it is saying invalid date ? But it is validating 19-Feb-2012. Why this issue ? How do i solve ?

/((([0][1-9]|[12][\d])|[3][01])[-\/]((Jan|Mar|May|Jul|Aug|Oct|Dec))[-\/][1-9]\d\d\d)|((([0][1-9]|[12][\d])|[3][0])[-\/]((Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))[-\/][1-9]\d\d\d)|(([0][1-9]|[12][\d])[-\/]((Feb))[-\/][1-9]\d([02468][048]|[13579][26]))|(([0][1-9]|[12][0-8])[-\/]((Feb))[-\/][1-9]\d\d\d)/i
SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Varshini S
Varshini S

ASKER

Thank you, it is working but if i give the date 29-Feb-2013 - it is not validating. Why ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
www.regexlib.com

has regular expressions for almost anything.  There is one on there that does exactly what you want.  Look under Date/Time.

Cheers.
Why use a regex for date validation? Why not use a CompareValidator?

e.g.  (http://stackoverflow.com/a/939852/884561)

<asp:CompareValidator
    id="dateValidator" runat="server" 
    Type="Date"
    Operator="DataTypeCheck"
    ControlToValidate="txtDatecompleted" 
    ErrorMessage="Please enter a valid date.">
</asp:CompareValidator>

Open in new window