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[0-9])|([12])([0-9]?)|(3[01]?))(-|\/)((\d{4})|(\d{2}))|(0?[2469]|11)(-|\/)((0[0-9])|([12])([0-9]?)|(3[0]?))(-|\/)((\d{4}|\d{2})))
Description
Regex used in .NET to validate a date. Matches the following formats mm/dd/yy, mm/dd/yyyy, mm-dd-yy, mm-dd-yyyy This covers days with 30 or 31 days but does not handle February, it is allowed 30 days.
Matches
1/31/2002 | 04-30-02 | 12-01/2002
Non-Matches
2/31/2002 | 13/0/02 | Jan 1, 2001
Author Rating: The rating for this expression. Sean McAnally
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: Almost
Name: Kevin
Date: 8/13/2013 11:59:47 AM
Comment:
Matches 1/1/0011


Title: UK, version with fixes.
Name: Barnaby
Date: 1/22/2008 7:54:00 AM
Comment:
Hi, I have moved this around so that it's in DD/MM/YYYY, I have also fixed it so that 00/01/2005 is not allowed and added ^ and $ Otherwise you will find that 41/12/2005 will match as (1/12/2005) ^(((0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)(0?[13578]|10|12)(-|\/)((\d{4})|(\d{2}))|((0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)(0?[2469]|11)(-|\/)((\d{4}|\d{2})))$


Title: it doesn't work all the time
Name: a.morgan
Date: 10/18/2006 8:37:16 PM
Comment:
Like the other say...it almost works


Title: No matches on days that are not zero-padded
Name: sb
Date: 1/27/2005 1:24:14 PM
Comment:
No matches on '3-7-2005'. To match non-zero-padded days as well, use: ((0?[13578]|10|12)(-|\/)(([0-9])|(0[0-9])|([12])([0-9]?)|(3[01]?))(- |\/)((\d{4})|(\d{2}))|(0?[2469]|11)(-|\/)(([0-9])|(0[0-9])|([12])([0 -9]?)|(3[0]?))(-|\/)((\d{4}|\d{2})))


Title: Almost the best!
Name: avi8tor
Date: 10/31/2004 11:40:20 PM
Comment:
Non matches on every test except... 2/30/2004 Feb 30 is a match


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