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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(((0[13578]|10|12)([-./])(0[1-9]|[12][0-9]|3[01])([-./])(\d{4}))|((0[469]|11)([-./])([0][1-9]|[12][0-9]|30)([-./])(\d{4}))|((2)([-./])(0[1-9]|1[0-9]|2[0-8])([-./])(\d{4}))|((2)(\.|-|\/)(29)([-./])([02468][048]00))|((2)([-./])(29)([-./])([13579][26]00))|((2)([-./])(29)([-./])([0-9][0-9][0][48]))|((2)([-./])(29)([-./])([0-9][0-9][2468][048]))|((2)([-./])(29)([-./])([0-9][0-9][13579][26])))
Description
My meager attempt at a date validator with leap years using a strict mm/dd/yyyy format.
Matches
02/29/2084 | 01/31/2000 | 11/30/2000
Non-Matches
02/29/2083 | 11/31/2000 | 01/32/2000
Author Rating: Not yet rated. Jason West
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: Invalid dates will match
Name: Michael Dean
Date: 9/5/2006 1:54:56 PM
Comment:
Hi, when testing, I was able to match on the value 2222/22/2222


Title: Some dates don't work but should
Name: Jeff
Date: 8/13/2004 10:29:55 AM
Comment:
12/30/2004, 12/31/2004, 07/30/2004, basically a bunch of the 30, and 31 days of the month don't work according to http://www.regexlib.com/RETester.aspx


Title: This doesn't work
Name: Randy
Date: 3/11/2004 6:58:55 PM
Comment:
This doesn't even match the first example of a match that you gave (02/29/2084). It won't except a 02 at the beginning. It will, however, except a 2 at the beginning. Pretty close, but not quite there yet.


Title: some feb dates do not require leading 0
Name: bob brinker
Date: 1/16/2004 10:26:22 AM
Comment:
i noticed that not all of the Feb dates (ie 02) require the leading 0. I corrected this issue...here is the updated REGEX: (((0[13578]|10|12)([-./])(0[1-9]|[12][0-9]|3[01])([-./])(\d{4}))|((0[469]|11)([-./])([0][1-9]|[12][0-9]|30)([-./])(\d{4}))|((02)([-./])(0[1-9]|1[0-9]|2[0-8])([-./])(\d{4}))|((02)(\.|-|\/)(29)([-./])([02468][048]00))|((02)([-./])(29)([-./])([13579][26]00))|((02)([-./])(29)([-./])([0-9][0-9][0][48]))|((02)([-./])(29)([-./])([0-9][0-9][2468][048]))|((02)([-./])(29)([-./])([0-9][0-9][13579][26])))


Title: Feb doesn't conform
Name: lars
Date: 7/8/2003 10:24:41 AM
Comment:
The regex works great, but doesn't force two digit month (mm) for February (e.g., will match 2/29/2084, but won't match 1/29/2084). How about: (((0[13578]|10|12)([-./])(0[1-9]|[12][0-9]|3[01])([-./])(\d{4}))|((0[469]|11)([-./])([0][1-9]|[12][0-9]|30)([-./])(\d{4}))|((2)([-./])(0[1-9]|1[0-9]|2[0-8])([-./])(\d{4}))|((02)(\.|-|\/)(29)([-./])([02468][048]00))|((02)([-./])(29)([-./])([13579][26]00))|((02)([-./])(29)([-./])([0-9][0-9][0][48]))|((02)([-./])(29)([-./])([0-9][0-9][2468][048]))|((02)([-./])(29)([-./])([0-9][0-9][13579][26])))


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