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])|(1[02]))[\/]?(([0-2][0-9])|(3[01])))|(((0[469])|(11))[\/]?(([0-2][0-9])|(30)))|(02[\/]?[0-2][0-9]))[\/]?\d{4}$
Description
Date expressions that matches MM/DD/YYYY where MM and DD must be two digits and zero padded. Validates correctly for all months except February, which it assumes to always have 29 days. The "/" separator is optional.
Matches
01/01/2001 | 02/29/2002 | 12/31/2002
Non-Matches
1/1/02 | 02/30/2002 | 1/25/2002
Author Rating: Not yet rated. Steven Smith
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: Perfect
Name: Nauman
Date: 8/30/2006 3:36:53 AM
Comment:
Hi, I required a regular expression for date validation (mm/dd/yyyy) in my ASP.NET application and I font Steven Smith's pattern perfect. Thanks.


Title: DD/MM/YYYY
Name: quanou
Date: 12/9/2005 6:51:00 AM
Comment:
OK, got it finally ! ^(((([1-2][0-9])|(0[1-9])|(3[01]))[\/]?((0[13578])|(1[02])))|((([1-2][0-9])|(0[1-9])|(30))[\/]?((0[469])|(11)))|(([1-2][0-9])|(0[1-9])[\/]?02))[\/]?\d{4}$


Title: Sorry
Name: quanou
Date: 12/8/2005 5:58:19 PM
Comment:
Oups, sorry for my last comment I tried to switch to DD/MM/YYYY and THAT doesn't work And I am still trying to make it work w/ no luck. So if u could help me on that, i really appreciate Thanks


Title: Nice work
Name: quanou
Date: 12/8/2005 5:51:30 PM
Comment:
Hi, i tested it but it doesn't seem to work for MM = 01 to 09, i may be wrong Nice work though !


Title: Re: Performance??
Name: Niko
Date: 1/11/2004 12:07:05 PM
Comment:
Dear Steve, Darran, please excuse my rude way of commenting this regex. It certainly was unrespectful to Steve who has contributed so many regexs to this page. My 'protest' was against the regex in terms of regular use, performance. As Steve wrote, used in a loop he would do it different, but still I don't 'like' it. Steve is mixing pattern matching with logic which in some circumstances works out brilliant by some tricky regular expressions, but in this case I think it's the wrong approach. I do love regular expressions and usually catch myself in doing allmighty regexs but in most cases it's not quite useful. Such a long regular expression might run fast for a quick validation, but when processing tons of data, you will recognize that mixing pattern matching with logic will let you sit in front of your code waiting for the process to end. At work we run pattern matching algorithms which process GB of data and I learned that quick detection if the data is of correct format l


Title: Constructive criticism is good
Name: Darren Neimke
Date: 1/8/2004 5:08:09 AM
Comment:
Niko, first a couple of things: - Yes, Steve is a friend of mine - Yes, I am the webmaster of this site ... right, now onto the message :-) I really value the fact that you took the time to offer feedback on this pattern. One of the main reasons that I added comments to the site ( there's also an Rss feed for them here http://www.regexlib.com/RssComments.aspx ) was so that users that visit this site in 6 months time from now would be able to read the comments and use them to help determine the quality of a pattern. Given that, it would also be good (for everyone) if, you could also take the time to mention why the pattern is so non-performant when providing feedback. Without inspecting the pattern too closely myself, I imagine that you are protesting against either the alternation or the amount of capturing that is going on. Anyways, I don't want to turn this into a rant, so to Niko, thanks again for your valuable input :-) and to Steve, stop writing sloppy


Title: Performance
Name: Steven Smith
Date: 1/8/2004 3:41:24 AM
Comment:
Honestly, no. I've never had a situation where a regular expression was impacting my application's performance. If I had to use one in a loop, I might look at it differently, but for validation, this is certainly 'fast enough'.


Title: Performance??
Name: Niko
Date: 1/8/2004 3:16:14 AM
Comment:
Ever considered performance when creating such a regex?


Title: Most Simply
Name: Hakim SALHI
Date: 8/20/2003 3:46:45 AM
Comment:
this regular expression is valid, and most simply ^[0-9]{4}-[0-9]{2}-[0-9]{2} Best Regards. Hakim SALHI umtsfr@free.fr http://umtsfr.free.fr


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