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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(?=\d)(?:(?!(?:(?:0?[5-9]|1[0-4])(?:\.|-|\/)10(?:\.|-|\/)(?:1582))|(?:(?:0?[3-9]|1[0-3])(?:\.|-|\/)0?9(?:\.|-|\/)(?:1752)))(31(?!(?:\.|-|\/)(?:0?[2469]|11))|30(?!(?:\.|-|\/)0?2)|(?:29(?:(?!(?:\.|-|\/)0?2(?:\.|-|\/))|(?=\D0?2\D(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|2[0-8]|1\d|0?[1-9])([-.\/])(1[012]|(?:0?[1-9]))\2((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?:$|(?=\x20\d)\x20)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$
Description
dd/mm/yyyy hh:MM:ss Datetime for all AD years, including leap years. Javascript safe version of http://regexlib.com/REDetails.aspx?regexp_id=691. Please see that regex for details of what is being checked
Matches
31.12.6008 | 5:30 AM | 30-04-1066
Non-Matches
00/00/0000 | 99:99:99 | 29/02/2005
Author Rating: The rating for this expression. Michael Ash
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: Add another regular expression
Name: Rene
Date: 2/12/2010 8:03:57 PM
Comment:
Good night Michael. I'm using your regexp, but I need make a change. I need validate dates separates for point and comma ';'. I was all the day trying it but finally I can´t. I took your redExk and I changed for this: ^(regExp without ^ and $)(?;?(regExp))*$ Please help me. Another thing. I don't understand the expression '(?' what do does it? You use it like prefix in all the regExp. Best Regards, René


Title: Add another regular expression
Name: Rene
Date: 2/12/2010 8:00:59 PM
Comment:
Good night Michael. I'm using your regexp, but I need make a change. I need validate dates separates for point and comma ';'. I was all the day trying it but finally I can´t. I took your redExk and I changed for this: ^(regExp without ^ and $)(?;?(regExp))*$ Please help me. Another thing. I don't understand the expression '(?' what do does it? You use it like prefix in all the regExp. Best Regards, René


Title: pattern title
Name: Nabin Paul
Date: 4/4/2009 12:01:07 PM
Comment:
^(?=d)(?:(?:(?:0?[1-4]|1[0-4]


Title: date-only version
Name: d. t.
Date: 8/22/2005 4:11:07 PM
Comment:
ok, I realized that if I only input dd/mm/yyyy, this regexp works good. However I never use the time part, so I trimmed the script just to save some space and ended up with: ^(?=\d)(?:(?!(?:(?:0?[5-9]|1[0-4])(?:\.|-|\/)10(?:\.|-|\/)(?:1582))|(?:(?:0?[3-9]|1[0-3])(?:\.|-|\/)0?9(?:\.|-|\/)(?:1752)))(31(?!(?:\.|-|\/)(?:0?[2469]|11))|30(?!(?:\.|-|\/)0?2)|(?:29(?:(?!(?:\.|-|\/)0?2(?:\.|-|\/))|(?=\D0?2\D(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|2[0-8]|1\d|0?[1-9])([-.\/])(1[012]|(?:0?[1-9]))\2((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?:$|(?=\x20\d)\x20)))\d{4}(?:\x20BC)?))?$ which worked for me... Many thanks for your date scripts, they are truly great!


Title: Re: simplified version
Name: Michael Ash
Date: 8/22/2005 3:27:26 PM
Comment:
Please see http://regexadvice.com/blogs/mash/archive/2004/06/17/309.aspx


Title: simplified version
Name: d. t.
Date: 8/22/2005 3:19:21 PM
Comment:
what is the value for this expression to validate only date (not time)? Also, this reg ex. can be used in .net? thanks


Title: Works fine
Name: damber
Date: 4/22/2005 7:26:20 PM
Comment:
Thanks again Michael, it is now working. p.s. I'm from the UK so am used to dates in the 'correct' format...... ;o) Keep up the good work - these expressions are saving me alot of coding time (and script space) !


Title: Re: I must be coding it wrong...
Name: Michael Ash
Date: 4/21/2005 10:48:46 AM
Comment:
Yeah you are having syntax issues. If you use the var re = new RegExp(pattern) syntax you have to escape all the backslashes. Try it with the var re = /pattern/ syntax See http://www.regular-expressions.info/javascript.html for more info BTW this pattern is dd/mm/yyyy so the date you are testing with is Feb 10th


Title: I must be coding it wrong...
Name: damber
Date: 4/20/2005 4:39:10 PM
Comment:
I tried the Regular Expression above in Firefox 1.01 and IE 6.0 using javascript as per the below: var dateRE = new RegExp('^(?=\d)(?:(?!(?:(?:0?[5-9]|1[0-4])(?:\.|-|\/)10(?:\.|-|\/)(?:1582))|(?:(?:0?[3-9]|1[0-3])(?:\.|-|\/)0?9(?:\.|-|\/)(?:1752)))(31(?!(?:\.|-|\/)(?:0?[2469]|11))|30(?!(?:\.|-|\/)0?2)|(?:29(?:(?!(?:\.|-|\/)0?2(?:\.|-|\/))|(?=\D0?2\D(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|2[0-8]|1\d|0?[1-9])([-.\/])(1[012]|(?:0?[1-9]))\2((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?:$|(?=\x20\d)\x20)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$'); return (dateRE.test(sDate)); it always returns false - for dates like 10.02.2005 or 10/02/2005... I've tried several other RE's from this site.. and none of them (date ones anyway) have worked... is this just my misunderstand


Title: Stepping back
Name: Michael Ash
Date: 7/21/2004 4:45:06 PM
Comment:
Modified to include Julian dates back to 45 BC.


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