- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
This expression is an attempt to match the most obvious features of a valid date in American/US format of the form mm/dd/yyyy for any year 1900 through 2003. It can easily be adapted for different date ranges. It matches any date where the day part is any number 01-31, the month part is any number 01-12, and the year part is any number 1900-2003. The only invalid dates that it matches are ones where the day part may be in the range 01-31 but that range might not be valid for the specified month. An example of an invalid date that it would allow to pass through would be 11/31/2002. This date is invalid because 11/31 of any year does not exist, but this expression would allow it pass through since the day part is in the range 01-31. This regular expression has been used successfully in ASP with VBScript using the windows scripting library RegExp object.
12/31/2003 | 01/01/1900 | 11/31/2002
1/1/2002 | 01/01/02 | 01/01/2004
Author Rating: Not yet rated. Josh Bailyr
Your Rating
Bad Good

Enter New 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: Less Broken
Name: More Fixed
Date: 8/29/2005 9:59:52 PM
Previous comment allowed 0 as month or day. Fixed: ^([1-9]|1[0-2])\/([1-9]|1\d|2\d|3[0-1])\/(19\d\d|200\d)$

Title: Broken
Name: Fixed
Date: 8/29/2005 8:58:48 PM
Didn't work for any date with a day from 10-19. Month and day were also too strict for typical validation use - most users don't enter dates with leading zeros like 01/01/2000, they type 1/1/2000. Both issues fixed here: ^(\d|0\d|1[0-2])\/(\d|0\d|1\d|2\d|3[0-1])\/(19\d\d|200\d)$

Copyright © 2001-2018, | ASP.NET Tutorials