RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find YYYY-MM-DD validation for dates from 1600 to 9999 with leap year check
Expression
^((1[6789]|[2-9][0-9])[0-9]{2}-(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))$|^((1[6789]|[2-9][0-9])[0-9]{2}-(0[469]|11)-(0[1-9]|[12][0-9]|30))$|^((16|[248][048]|[3579][26])00)|(1[6789]|[2-9][0-9])(0[48]|[13579][26]|[2468][048])-02-(0[1-9]|1[0-9]|2[0-9])$|^(1[6789]|[2-9][0-9])[0-9]{2}-02-(0[1-9]|1[0-9]|2[0-8])$
Description
This regular expression checks dates from 1600 to 9999 in the form of YYYY-MM-DD also takes into account leap years tested in PHP with PCRE
Matches
1600-02-29 | 1971-01-31 | 2003-04-30
Non-Matches
2000-11-31 | 1807-02-29
Author Rating: Not yet rated. Koen de Boeve
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: corrected leap check should be ok now
Name: Koen de Boeve
Date: 11/5/2007 6:23:26 PM
Comment:
You are right Michael thx ! I made some changes and I think I fixed it... feel free to double check


Title: Leap year check incorrect
Name: Michael Ash
Date: 11/5/2007 10:57:14 AM
Comment:
The leap year check is incomplete. Your regex will match 2100-02-29 which incorrect. 2100 is not a leap year. Also the way you have constructed the leap year check allows it to match outside of the stated boundary 1100-02-29 also matches.


Copyright © 2001-2018, RegexAdvice.com | ASP.NET Tutorials