Title |
Test
Find
ISO 8601 Date validation with long-short months and leap years
|
Expression |
^(?:(?=[02468][048]00|[13579][26]00|[0-9][0-9]0[48]|[0-9][0-9][2468][048]|[0-9][0-9][13579][26])\d{4}(?:(-|)(?:(?:00[1-9]|0[1-9][0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-6])|(?:01|03|05|07|08|10|12)(?:\1(?:0[1-9]|[12][0-9]|3[01]))?|(?:04|06|09|11)(?:\1(?:0[1-9]|[12][0-9]|30))?|02(?:\1(?:0[1-9]|[12][0-9]))?|W(?:0[1-9]|[1-4][0-9]|5[0-3])(?:\1[1-7])?))?)$|^(?:(?![02468][048]00|[13579][26]00|[0-9][0-9]0[48]|[0-9][0-9][2468][048]|[0-9][0-9][13579][26])\d{4}(?:(-|)(?:(?:00[1-9]|0[1-9][0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-5])|(?:01|03|05|07|08|10|12)(?:\2(?:0[1-9]|[12][0-9]|3[01]))?|(?:04|06|09|11)(?:\2(?:0[1-9]|[12][0-9]|30))?|(?:02)(?:\2(?:0[1-9]|1[0-9]|2[0-8]))?|W(?:0[1-9]|[1-4][0-9]|5[0-3])(?:\2[1-7])?))?)$ |
Description |
Validate a date according to the ISO 8601 standard (no time part) considering long-short months to allow 31st day of month and leap years to allow 29th February. I took Ted Cambron's implementation, simplified and added support for leap years and long-short months. |
Matches |
1600-02-29 |
Non-Matches |
2011-02-29 |
Author |
Rating:
Robert Ševčík (Robajz)
|
Source |
http://regexlib.com/REDetails.aspx?regexp_id=2092 |
Your Rating |
|
Title: Nice
Name: Ted Cambron
Date: 9/24/2014 7:50:26 PM
Comment:
I can't believe the rating is so low on this little gem.
Title: More readable version
Name: Robajz
Date: 8/28/2011 11:08:15 AM
Comment:
I posted an indented version on StackOverflow: http://stackoverflow.com/questions/3143070/javascript-regex-iso-datetime/7221570#7221570