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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Validate dates from 1/1/0001 to 12/31/9999
Expression
^(?=0?[1-9]/|1[012]/)(?:(?<month>(?<month31days>0?[13578]|1[02])|(?<month30days>0?[469]|11)|(?<monthFeb>0?2))/)(?<day>(?(month31days)(?:[012]?[1-9]|3[01]))(?(month30days)(?:[012]?[1-9]|30))(?(monthFeb)(?:[01]?[1-9]|2(?(?=\d/(?:(?:(?:04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)00)|(?:\d\d(?:04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96))))[0-9]|[0-8]))))/(?<year>(?!0000)\d{4})$
Description
Validates dates from 1/1/0001 to 12/31/9999. Month and day can be preceded by a zero to a max of two digits; however, year must be four digits exactly. This regex was developed in a .NET environment and uses conditional lookahead syntax, so your regex engine must support same. Month, day, and year are captured to groups named "month", "day", and "year" for additional processing if desired.
Matches
2/29/2000 | 01/01/0001 | 9/18/2009
Non-Matches
2/29/2100 | 4/31/2009 | 001/31/2009
Author Rating: Not yet rated. Jerry Schmersahl
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

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