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?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$
Description
Date with leap years. Accepts '.' '-' and '/' as separators d.m.yy to dd.mm.yyyy (or d.mm.yy, etc) Ex: dd-mm-yyyy d.mm/yy dd/m.yyyy etc etc Accept 00 years also.
Matches
29.2.2004 | 31121975 | 29/2-00
Non-Matches
29.2.2005 | 32121975 | 29.2/01
Author Rating: The rating for this expression. Dany Lauener
Source This forum has helped, but too much bad regexp for dates. Author: [email protected]
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: Very Goog
Name: Mike
Date: 1/27/2016 5:25:57 AM
Comment:
Thks Life Saver


Title: Require 4 digit year
Name: [email protected]
Date: 6/27/2008 10:48:20 AM
Comment:
Is there a version that requires 4 digit years? This one seems to accept 2 digit years.


Title: "\ " unrecognised escape sequence
Name: sushma
Date: 1/4/2008 4:58:45 AM
Comment:
I am getting ASP.NEt unrecoginized escape error while compilation


Title: one question
Name: alex
Date: 5/28/2007 6:35:15 PM
Comment:
one question: 09 as yy is 1907 or 2009 and 12 as yy is 1912 or 2012


Title: ASP.NEt unrecoginized escape
Name: C3
Date: 5/23/2006 1:15:41 PM
Comment:
You need an @ before the regex's to avoid Visual Studio giving you an error. so RegEx.IsMatch(input, @"...");


Title: Other versions?
Name: Geoff Caylor
Date: 8/9/2004 3:19:06 PM
Comment:
Hello. Great expression! However, I'm looking for one in a different format? Do you have one, or does any other reader know of one that handles the following formats? MMDDYY, MMDDYYYY, MM/DD/YY, MM/DD/YYYY TIA, G


Title: For Mike request
Name: Dany Lauener
Date: 4/13/2004 3:57:44 PM
Comment:
here it comes. As I discovered into your email that you do not need DDMMYYYY validation, I removed it... se here : http://www.regexlib.com/REDetails.aspx?regexp_id=666


Title: Extend regexp to handle 1 digit year date
Name: Mike
Date: 4/13/2004 9:43:39 AM
Comment:
After must testing I found this regexp to be the only one to work in all the cases I required, except 1. I need to extend it so that it also accepts 1 digits years (which I will convert with javascript from 0 to 2000, 1 to 2001, etc). I've no experience with regular expression and am finding this probably easy task impossible to complete. Thanks in advance for any help.


Title: Mr
Name: Thomas Keegan
Date: 4/1/2004 4:38:50 AM
Comment:
Excellent, no better word to describe it


Title: date
Name: pierpaolo
Date: 3/11/2004 2:08:59 PM
Comment:
YYYYMMGGhhmmss


Title: dd-mmm-yyyy
Name: Michael Ash
Date: 2/19/2004 10:13:27 AM
Comment:
Here's one in that format. http://www.regexlib.com/REDetails.aspx?regexp_id=405 although it only uses spaces for separators so would still need slight modification


Title: dd-MMM-yyyy
Name: Dany
Date: 2/19/2004 9:11:59 AM
Comment:
I'll do one for you if I have time. It's easy... I will be longer because not numeric, but whatever... Best regards. Dany


Title: dd-MMM-yyyy
Name: Peter
Date: 2/19/2004 9:07:17 AM
Comment:
I think this is one of the best regular expressions i have ever seen. Q: What can be done for this to take dates like: "01-Jan-2003" or: "12-Dec-2004" ... ?? or: 14 Feb 2004 ? format for .NET is: "dd-MMM-yyyy" How can this be done?


Title: Doesn't seem to be written for it :)
Name: Dany
Date: 12/8/2003 2:28:18 AM
Comment:
On earth, there's sometimes something strange. A metric system exists, as well as a "logical" way to go from the smallest part to he biggest : days, then months, then years. DD/MM/YY With a touch of humour.


Title: Got a problem..
Name: Paul S
Date: 12/5/2003 4:25:23 PM
Comment:
Doesn't seem to work with 13 or higher in the middle group of digits. For example, 02/12/03 works but 02/13/03 does not.


Title: KickAss!
Name: Macca
Date: 12/4/2003 4:04:26 AM
Comment:
Well-done, and thank you.


Title: Re: Cool, but
Name: Michael Ash
Date: 11/12/2003 9:59:13 AM
Comment:
Here is one in MM/DD/YYYY format http://www.regexlib.com/REDetails.aspx?regexp_id=113


Title: Cool, but..
Name: TK
Date: 11/11/2003 1:36:57 PM
Comment:
Can someone please convert this regexp to handle MMDDYYYY instead of DDMMYYYY?


Title: ASP.NET
Name: Bert
Date: 10/30/2003 5:10:28 AM
Comment:
Does anyone know how to convert the expressions so i dont get the unrecognized escape sequence error. When i copy them into a string i currently i have the error saying unrecognized escape sequence.


Title: FANTASTIC
Name: Tony
Date: 10/30/2003 4:47:01 AM
Comment:
That reg ex is fantastic... It works so nicely and is extremely extensive... EXCELLENT WORK my good man


Title: Jakarta regexp
Name: Dany Lauener
Date: 9/26/2003 3:08:13 AM
Comment:
Hi Thiago, try to replace [\.\-\/] with [:punct:] you can find docs about regexp in jakarta here : http://jakarta.apache.org/regexp/apidocs/org/apache/regexp/RE.html or java help here: http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/regexp.html Please, note that this regexp should be java compliant. Note also the "red" issues of jakarta. Hope this helps. Dany


Title: True coder spirit shown
Name: Henrik
Date: 9/20/2003 7:12:26 AM
Comment:
Hi Dany Thank you for this extremely useful regex. I'm a CTO in a software company, where the pressure hits the roof every day and have no time to sit down and create an expression like this. I'm going to use it in a high profile app for a Scandinavian company. You have already been credited. Thanks again.


Title: Your welcome
Name: Dany
Date: 9/16/2003 8:51:39 AM
Comment:
Your welcome guys ! The secret is to separate your expression into very simple working (and 100% tested) regexp, and then respect the logical way to construct a bigger one, and so on... If you wan, I've got a file with separated expressions (basic month validator, for example, then day validator, then leap year, then non leap year, etc...) send me a mail.


Title: Cool - at last the one that seems to work in all cases
Name: Jacek
Date: 8/9/2003 8:59:21 AM
Comment:
Thanks for posting this regexp!


Title: WOW - ONE THAT WORKS
Name: Steve
Date: 7/30/2003 10:43:22 AM
Comment:
Too many posted regex's do not work. AFter testing 12-15 posted regexes, this is the first that I have found that has passed ALL of my tests. It may still fail some, but works better than any I have found so far. Well done Dany!


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