RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find M/d/y Date
Expression
^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[13-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
Description
This expression validates dates in the US m/d/y format from 1/1/1600 - 12/31/9999.
Matches
01.1.02 | 11-30-2001 | 2/29/2000
Non-Matches
02/29/01 | 13/01/2002 | 11/00/02
Author Rating: The rating for this expression. Michael Ash
Source Michael Ash
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: www.GameGoldFactory.com
Name: www.GameGoldFactory.com
Date: 11/18/2012 10:12:55 PM
Comment:
www.GameGoldFactory.com


Title: www.GameGoldFactory.com
Name: www.GameGoldFactory.com
Date: 11/18/2012 10:12:51 PM
Comment:
www.GameGoldFactory.com


Title: www.GameGoldFactory.com
Name: www.GameGoldFactory.com
Date: 11/18/2012 9:58:47 PM
Comment:
www.GameGoldFactory.com


Title: www.GameGoldFactory.com
Name: www.GameGoldFactory.com
Date: 11/18/2012 9:57:01 PM
Comment:
www.GameGoldFactory.com


Title: www.GameGoldFactory.com
Name: www.GameGoldFactory.com
Date: 11/18/2012 9:56:49 PM
Comment:
www.GameGoldFactory.com


Title: Regular Expression for DD/MM/YYYY DD-MM-YYYY DD.MM.YYYY
Name: Beginner
Date: 10/11/2012 5:48:49 AM
Comment:
Hi, I am looking for a regex to validate the date with the below criteria: 1) Format DD/MM/YYYY,DD.MM.YYYY,DD-MM-YYYY 2) Leap Year Validation 3) Month date validation (Example :Should not accept 31st for April, June, November..) Please help me on this. Thanks


Title: Expression in DD/MM/YYYY format
Name: Beginner
Date: 10/10/2012 9:20:25 AM
Comment:
please provide date dd/mm/yyyy format. it should accept 30,31 days for respective months and also leap years. special condition is it should allow only present and future dates only. plz Thanks in advance!


Title: Expression in DD/MM/YYYY format
Name: Beginner
Date: 10/10/2012 9:18:17 AM
Comment:
please provide date dd/mm/yyyy format. it should accept 30,31 days for respective months and also leap years. special condition is it should allow only present and future dates only. plz Thanks in advance!


Title: NIKE
Name: NIKE
Date: 2/27/2012 8:17:49 AM
Comment:
<a href="http://www-chanelhandbags.co.uk/" title="chanel bags">chanel bags</a> Escapism for the soul. A love-fuelled flight that never leaves the ground! Adulation permeates the Spring-Summer 2012 Haute Couture collection: adulation of excellence, materials, showmanship, and the adored accomplishment of artisan craftsmen adherent to Chanel. Lagerfeld’s faculty of amusement is present, as well… “Catch me if you can”: Tuesday, January 24th, in the Grand Palais, aboard a accurate replica of an aircraft cabin, something of the airy spirit of the sixties was in the air with its belief of air biking in those Pan Am years. Mischievous-looking air hostesses, auspicious apple-pie curve and a balmy breeding accustomed in 2012 with smiles all around. No Business Class here; anybody is built-in in First Class – this is capitalism according to Chanel! www-chanelhandbags.co.uk


Title: NIKE
Name: NIKE
Date: 2/27/2012 8:17:03 AM
Comment:
<a href="http://www-chanelhandbags.co.uk/" title="chanel bags">chanel bags</a> Escapism for the soul. A love-fuelled flight that never leaves the ground! Adulation permeates the Spring-Summer 2012 Haute Couture collection: adulation of excellence, materials, showmanship, and the adored accomplishment of artisan craftsmen adherent to Chanel. Lagerfeld’s faculty of amusement is present, as well… “Catch me if you can”: Tuesday, January 24th, in the Grand Palais, aboard a accurate replica of an aircraft cabin, something of the airy spirit of the sixties was in the air with its belief of air biking in those Pan Am years. Mischievous-looking air hostesses, auspicious apple-pie curve and a balmy breeding accustomed in 2012 with smiles all around. No Business Class here; anybody is built-in in First Class – this is capitalism according to Chanel! www-chanelhandbags.co.uk


Title: Expression in DD.MM.YYYY format
Name: Gopal
Date: 12/13/2011 6:08:52 AM
Comment:
Hello Expert, I need the expression for DD.MM.YYYY format. Please provide. Thanks a lot !!


Title: Expression in DD.MM.YYYY format
Name: Gopal
Date: 12/13/2011 6:04:56 AM
Comment:
Hello Expert, I need the expression for DD.MM.YYYY format. Please provide. Thanks a lot !!


Title: toseyr
Name: toseyr
Date: 12/2/2011 8:02:02 PM
Comment:
one <a href=http://www.toseyr.com/toseyr.html>toseyr</a> ande [url=http://www.toseyr.com/toseyr.html]toseyr[/url] or toseyr http://www.toseyr.com


Title: Help with expression
Name: Satish P
Date: 11/9/2011 8:33:44 AM
Comment:
Required regular expression format mm/dd


Title: Help with Expression
Name: Kwaku
Date: 8/9/2011 12:30:56 PM
Comment:
Hi, I am so new to these stuff. I want to validate a textbox containing either alphabets or numbers or both. i.e : field should accept : numbers,alphabeths and alphanumeric . I need this to validate an ID field with no fixed format minimun value for field=6 maximun value for field = 13 Thanks


Title: Regular expression for dd-MM-yyyy format
Name: Balwant Singh
Date: 3/12/2011 1:25:23 AM
Comment:
Hi Budy! I am looking for date format dd-MM-yyyy as indian style.


Title: Regular expression for dd-MM-yyyy format
Name: Balwant Singh
Date: 3/12/2011 1:24:23 AM
Comment:
Hi Budy! I am looking for date format dd-MM-yyyy as indian style.


Title: Regular Expression for MM/DD/YYY MM-DD-YYY MM.DD.YYYY
Name: sarath
Date: 2/1/2011 9:03:11 AM
Comment:
Hi, I am looking for a regex to validate the date with the below criteria: 1) Format MM/DD/YYYY,MM.DD.YYYY,MM-DD-YYYY 2) Leap Year Validation 3) Month date validation (Example :Should not accept 31st for April, June, August..) Please help me on this. Thanks, Sarath


Title: Regular Expression for MM/DD/YYY MM-DD-YYY MM.DD.YYYY
Name: sarath
Date: 2/1/2011 9:00:16 AM
Comment:
Hi, I am looking for a regex to validate the date with the below criteria: 1) Format MM/DD/YYYY,MM.DD.YYYY,MM-DD-YYYY 2) Leap Year Validation 3) Month date validation (Example :Should not accept 31st for April, June, August..) Please help me on this. Thanks, Sarath


Title: zzgg
Name: zg
Date: 11/24/2010 3:57:18 PM
Comment:
This is a problem related to .php. A string containing regular words. I need to extract an array of occurrences of <#adjective#>, <#noun#>, etc. and convert them into a textfield input, whereas any occurrences of <#him/her#> should be convereted into a radio button. Thanks.


Title: zzgg
Name: zg
Date: 11/24/2010 3:56:01 PM
Comment:
This is a problem related to .php. A string containing regular words. I need to extract an array of occurrences of <#adjective#>, <#noun#>, etc. and convert them into a textfield input, whereas any occurrences of <#him/her#> should be convereted into a radio button. Thanks.


Title: can u help me to write a expression to validate MMDDYY MMDDYYYY,MM/DD/YY,MM/DD/YYYY,MM-DD-YY,MM-DD-YYYY
Name: Rudra p Malla
Date: 3/3/2009 4:43:35 AM
Comment:
can u help me to write a expression to validate MMDDYY MMDDYYYY,MM/DD/YY,MM/DD/YYYY,MM-DD-YY,MM-DD-YYYY i:e 010209 ,01022009 i little bit modify ur script as follows ^(?:(?:(?:0?[13578]|1[02])(\/|-|)31)\1|(?:(?:0?[13-9]|1[0-2])(\/|-|)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$ which help me to validate 01022009,01022009, but it also validate 1212009 which should not. as it represent todays either 1/21/2009 or 12/1/2009 i want only user should enter in the format as follows 12012009 please help me. thankd and regards Rudra p Malla


Title: HOW COME BACK REFERENCES ARE NEED FOR IT TO WORK
Name: lost on backreferences
Date: 1/4/2009 8:44:34 PM
Comment:
How come the back references are needed for the expression to work? If the \1,\2 , \3 and so on if remove the expression doe not work? I thought when ?: is used no back referencing is done. If someone can explain why the back references are needed for the expression to work please email me at [email protected] ^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$


Title: Experssion for YYYY-MM-DD
Name: Leela
Date: 7/24/2008 9:41:13 AM
Comment:
Hi, I have a regular expression which gives me the date format in YYYY/MM/DD but it does not validate leap year and accepts a date like 2000/02/30 Can anyone help? Regards, Leela


Title: Add "/"
Name: Anoopj
Date: 11/20/2006 8:54:21 AM
Comment:
it works fine for me after adding a "/" in begining and end, thanks a lot


Title: Re: Need help for yyyy format
Name: Michael Ash
Date: 12/21/2005 10:36:26 AM
Comment:
See http://regexadvice.com/blogs/mash/archive/2004/06/17/309.aspx for alternate date formats


Title: Need help for yyyy format
Name: sandy
Date: 12/21/2005 1:29:22 AM
Comment:
this Expression is working fine. but i need help for the forceful acceptance of 4 year digit. I tried the answer given below but its not working.


Title: SE
Name: Dave Crossman
Date: 8/9/2005 7:09:06 PM
Comment:
The character class [1,3-9] should be [13-9]


Title: Re: Regex checking date in (YYYY/MM/DD) format
Name: Michael Ash
Date: 6/13/2005 10:17:40 AM
Comment:
Well I have posted yyyy/mm/dd format already. See http://regexadvice.com/blogs/mash/archive/2004/06/17/309.aspx for more details on alternate formats.


Title: Regex checking date in (YYYY/MM/DD) format.
Name: Trivendra Gupta
Date: 6/13/2005 8:03:36 AM
Comment:
Hi, I had tried to customize the given Regex to solve my requirment. Please try the following regex and let me know it there is any problem with this regex. You can mail me at [email protected]. ^(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)))$|^(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)0?2(\/|-|\.)29)$|^(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])$ Thanks Trivendra Gupta India.


Title: RE: C# Error "Unrecognized Escape Sequence"
Name: Michael Ash
Date: 6/7/2005 12:49:05 PM
Comment:
It worked fine for me. I just ran a test app with VS2005. Did you forget to prefix the string defining the regex with the at sign? (@)


Title: C# Error "Unrecognized Escape Sequence"
Name: RHPT
Date: 6/6/2005 11:07:56 AM
Comment:
Michael, I am using Visual Studio 2005 (beta 2), and when I try to use this RE, it gives the error "Unrecognized Escape Sequence" error for "\". Do you have any idea why this is happening and if there is a workaround? Thanks.


Title: Mr.
Name: Frank
Date: 4/16/2005 5:59:34 PM
Comment:
Exceptional.


Title: forget my .NET support? note
Name: adf
Date: 11/14/2003 6:48:37 PM
Comment:
It works with the ^ and $.


Title: .NET support?
Name: adf
Date: 11/14/2003 6:45:24 PM
Comment:
Michael, If the ^ and $ are required for integrity, then can you suggest ways to work your RE in .NET? thanks -adf


Title: Thanks
Name: Kuljeet Sidhu
Date: 11/13/2003 3:11:06 PM
Comment:
Hey Michael, Thanks for the great expression. Works like a charm in my validator. K.


Title: VP
Name: Steve Donnelly
Date: 10/21/2003 10:12:00 AM
Comment:
Works great for me in my VBScript function in ASP


Title: Re: It does not work for 01/01/0000
Name: Michael Ash
Date: 10/13/2003 4:20:58 PM
Comment:
It's not suppose to. Works for the year 1600 to 9999


Title: It does not work for 01/01/0000
Name: Functoid
Date: 10/13/2003 4:15:16 PM
Comment:
It does not work for 01/01/0000. can anybody suggest a solution. Thx


Title: Re: (?:
Name: Michael Ash
Date: 10/10/2003 10:01:45 AM
Comment:
(?:) is a non-capturing group. Normally expressions within parentheses are remembered by the RE as a subexpression. These subexpression can later be backreferenced later in the RE. The (?:) doesn't capture the subexpression for later use. In this particular expression the only subexpression I want to remember is the date separator after the months, so I can check to make sure the same separator is used after the days.


Title: (?:
Name: Tim Johnson
Date: 10/10/2003 6:27:59 AM
Comment:
I'm trying to understand the regexp, but can't find any docs describing (?: ...). What does this expression do? Thanks.


Title: re: problems with usage
Name: Michael Ash
Date: 10/8/2003 10:47:21 AM
Comment:
Just a word of warning for those of you using this expression, who have removed the leading ^ and trailing $, you may want to triple check the RE because without a boundry of some kind around it some bad values may slip thru For example, while 13/31/2003 will fail this expression as it is written here, without the ^ and $ it may pass because there is a valid date within the string (3/31/2003) Basically the month and the year would have no upper bound. If you removed the intermediate ^'s & $'s, the leap year validations could fail too. ex: 2/29/2003 would pass because 2/29/20 within the string is valid


Title: Re: DD/MM/yyyy
Name: Michael Ash
Date: 9/26/2003 5:26:31 PM
Comment:
Click on patterns at the top of the page, then click on the date/time tab. There are several there including a modifacton of this one.


Title: DD/MM/yyyy
Name: André
Date: 9/26/2003 4:46:05 PM
Comment:
Hi, I Need a Validator Expression for dd/mm/yyyy. Can Anyone Help me ? Thanks! André


Title: yyyy/mm/dd Format
Name: Swarnjit Sambhi
Date: 9/11/2003 12:55:40 PM
Comment:
Thanks Michael! I appreciate the quick response.


Title: RE: Need yyyy\mm\mm format instead
Name: Michael Ash
Date: 9/11/2003 11:19:15 AM
Comment:
I've already posted a yyyy/mm/dd RE on this library. http://www.regexlib.com/REDetails.aspx?regexp_id=190 Works the same as this one except for the format


Title: Need yyyy\mm\mm format instead
Name: Swarnjit Sambhi
Date: 9/10/2003 7:44:43 PM
Comment:
Hi, This regex is awesome but I can't seem to alter it to test for yyyy\mm\dd format instead. Can anyone help? Thanks!


Title: re: problems with usage
Name: Mark Roberts
Date: 9/2/2003 9:47:08 AM
Comment:
William, I tried your suggestion (removing leading ^ and trailing $) and it seems to work for me as well. Thanks for your help.


Title: problems with usage
Name: william newsom
Date: 8/30/2003 12:15:15 PM
Comment:
i left out the beginning ^ and the ending $ and its seems to work.


Title: ASP.NET Validator Usage
Name: Mark Roberts
Date: 8/29/2003 10:59:31 AM
Comment:
This RE is just what I'm looking for for bullet-proof date validation in an ASP.NET app I'm working on. I tried pasting this RE into an ASP.NET regular expression validator and it seems to reject invalid AND valid dates. Can anyone share any light on .NET differences? Thanks


Title: Re: Agreeing about IE
Name: Michael Ash
Date: 8/18/2003 12:39:26 PM
Comment:
I haven't had any problem with IE myself, so I'm not exactly sure why others are having problems. I've used a few different RE testers to test it and they worked fine. 2/29/2003 was flagged no match. For those having problems how are you implimenting the RE? I was orginally using vbscript but modified it later for Java and javascript. I'm fairly sure I was testing on IE v5 at first.


Title: Agreeing about IE
Name: Justin
Date: 8/17/2003 11:18:18 PM
Comment:
I'm having the same IE problem as the guy above. 2/29/2003 doesn't get caught. However your regex works on this site's tester. Maybe there is a character limit in IE browsers? Kudos to you for coming up with such a crazy regex. Interesting about the Gregorian calendar too.


Title: Re: Re: Every 00 is a leap year
Name: Yohan
Date: 8/12/2003 4:52:30 PM
Comment:
Yep, you were right. I figured you were because you wrote this this complicated RE and I wondered how you could miss something that I thought was very obvious. Nice job BTW: I've used your RE on several occasions.


Title: Re: Every 00 is a leap year
Name: Michael Ash
Date: 8/12/2003 9:51:43 AM
Comment:
In reply to Yohan's comment: Every year ending is 00 is not a leap year. See http://aa.usno.navy.mil/faq/docs/leap_years.html for more detail The Rule According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years. This is what this RE is based on.


Title: Every 00 is a leap year...
Name: Yohan
Date: 8/11/2003 2:51:29 PM
Comment:
In reply to Michael Ash's comment: Every year ending with 00 is a leap year. Leap years happen every four years, so therfore every 100 years (25 leap years) it will be a leap year again.


Title: Re: Year 2000 leap year problem for two digit year
Name: Michael Ash
Date: 8/4/2003 5:32:10 PM
Comment:
As stated in the description Feb 29 will not validate for the year 00. That is intentional since this RE was designed with the idea of being able to used until the year 9999 and not all years ending in 00 are leap years. 4 digit years validate for every century within the given range, however.


Title: userwx
Name: wxx
Date: 8/4/2003 5:18:42 AM
Comment:
some date can not be used


Title: Time
Name: Dan
Date: 6/17/2003 3:58:42 PM
Comment:
Would be nice if this was altered to validate for time as well.


Title: 4 year digits
Name: D
Date: 6/5/2003 10:49:51 AM
Comment:
i believe you can remove the `?' at the 108th character and very last `?' to force it to accept only 4 year dates, although i'd leave this one alone run run an additional check before/after for 4 year dates. It is a beast to understand! i read it by breaking it up into its principle parts, at the three `$' even then it still took about 5 minutes, hehe, my screensaver kicked in... time to go rub my eyes.


Title: Force 4 year validations
Name: C.S. Lewis
Date: 6/4/2003 1:46:59 PM
Comment:
I would like to see this reg exp modified slightly to accept only 4 digit years. This one is a beast to understand.


Title: Year 2000 leap year problem for two digit year
Name: Freddie G. Meyer
Date: 4/30/2003 2:10:19 PM
Comment:
Year 2000 is a leap year, and 2/29/2000 does validate. But 2/29/00 does not validate.


Title: IE5.0
Name: Jip Moors
Date: 4/12/2003 4:56:27 AM
Comment:
Its seems to work in any browser .. except Internet Exploder 5.0.


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