Link to home
Start Free TrialLog in
Avatar of rtay
rtayFlag for United States of America

asked on

Regulare Expression Validator for date that also allows field to remain blank

I have an optional date field.  This field needs to be checked for proper date mm/dd/yyyy or if blank allow the null.  This feild can have a date in it, and then the user will null the date out if no longer needed.  The validator I use always checks for the date and so does not allow the null.  

Thanks for the help
Avatar of sjklein42
sjklein42
Flag of United States of America image

(^$)|(^(0[1-9]|[12][0-9]|3[01])\-(0[1-9]|1[0-2])\-([12][0-9][0-9][0-9])$)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sjklein42
sjklein42
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
Avatar of rtay

ASKER

Was this regex supposed to allow the field to be null as well as validate the date?
Yes.  It accepts either an empty string or a valid date.
Avatar of kaufmed
A slightly shorter version  : )
^(?:(?:0[1-9]|[12]\d|3[01])/(?:0[1-9]|1[012])/(?:[12]\d{3}))?$

Open in new window