Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dd/mm/yyyy regular expression

Status
Not open for further replies.

mrp9090

Programmer
May 22, 2006
71
GB
Does anybody have a regular expression to validate dates in format dd/mm/yyyy e.g. 09/05/2006?

Any help would be much appreciated!
 
(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])

-DNG
 
oops...try this:

(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d

-DNG
 
This one has as few flaws, first of all it is mm/dd instead of dd/mm which is easy enough to correct, but it doesn't prevent dates like 30/02 etc which are invalid. Is it possible to write a regex that does this? Maybe you would have to limit the years to 2004, 2005, 2006, 2007, 2008, so that you can only accept these years and so that you can check for the leap year for these years.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top