I'm trying to write a regular expression that validates a date. The regex needs to match the following
- M/D/YYYY
- MM/DD/YYYY
- Single digit months can start with a leading zero (eg: 03/12/2008)
- Single digit days can start with a leading zero (eg: 3/02/2008)
- CANNOT include February 30 or February 31 (eg: 2/31/2008)
So far I have ^(([1-9]|1[012])-/.-/.\d\d)|((1[012]|0[1-9])(3[01]|2\d|1\d|0[1-9])(19|20)\d\d)|((1[012]|0[1-9])-/.-/.\d\d)$
This matches properly EXCEPT it still includes 2/30/2008 & 2/31/2008.
Does anyone have a better suggestion?
Edit: I found the answer on RegExLib
^((((0[13578])|([13578])|(1[02]))[\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\/](([1-9])|([0-2][0-9]))))[\/]\d{4}$|^\d{4}$
It matches all valid months that follow the MM/DD/YYYY format.
Thanks everyone for the help.