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)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$
Description
DateTime Validator. This RE validates both dates and/or times patterns. Days in Feb. are also validated for Leap years. Dates: in dd/mm/yyyy or d/m/yy format between 1/1/1600 - 31/12/9999. Leading zeroes are optional. Date separators can be either matching dashes(-), slashes(/) or periods(.) Times: in the hh:MM:ss AM/PM 12 hour format (12:00 AM - 11:59:59 PM) or hh:MM:ss military time format (00:00:00 - 23:59:59). The 12 hour time format: 1) may have a leading zero for the hour. 2) Minutes and seconds are optional for the 12 hour format 3) AM or PM is required and case sensitive. Military time 1) must have a leading zero for all hours less than 10. 2) Minutes are manditory. 3) seconds are optional. Datetimes: combination of the above formats. A date first then a time separated by a space. ex) dd/mm/yyyy hh:MM:ss This RE is an variation of one of my other Datetime (mm/dd/yyyy) validator already in this library http://www.regexlib.com/REDetails.aspx?regexp_id=369, so the same rules for leap year apply. All 4 digit year and all two digit years except 00, which might not be a leap year.
Matches
31/12/2003 11:59:59 PM | 29-2-2004 | 01:45:02
Non-Matches
12/31/2003 | 29.02.2005 | 13:30 PM
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: sorry but what is the regular expression for date format dd-m-yyyy
Name: paolo
Date: 7/21/2022 7:54:10 PM
Comment:
thank youuu


Title: how to validate birth days between a certain interval ?
Name: Silviu
Date: 11/28/2013 10:31:04 AM
Comment:
I am using the regex below to validate european date DD/MM/YYYY for clients date of birth. However, Clients might enter a date in the future, or be less than 18 y.o. which shouldn't validate. I guess I should also programatically alter the regex each year to keep up with the 18yo restriction. Here is the regex I use, I took it from this website, but cannot see it anymore, if anyone could point me out in the right direction, or was it updated to a newer version? ((31([-/ ])((0?[13578])|(1[02]))\3(\d\d)?\d\d)|((([012]?[1-9])|([123]0))([-/ ])((0?[13-9])|(1[0-2]))\12(\d\d)?\d\d)|(((2[0-8])|(1[0-9])|(0?[1-9]))([-/ ])0?2\22(\d\d)?\d\d)|(29([-/ ])0?2\25(((\d\d)?(([2468][048])|([13579][26])|(0[48])))|((([02468][048])|([13579][26]))00))))\


Title: Thanks
Name: Jack
Date: 3/21/2013 3:02:57 AM
Comment:
Thank u sir, that's what im searching for, good stuff


Title: Allow on digit hour values
Name: Dominik Enkelmann
Date: 12/29/2011 7:04:12 AM
Comment:
Why not allow hours expressed with only one digit? I changed the end of the exp to: [AP]M))|(([01]\d|2[0-3])|\d)(:[0-5]\d){1,2})?$


Title: Didn't know you existed
Name: Leon
Date: 10/17/2011 1:06:02 AM
Comment:
I really like your approach, I have not yet used your regular expression, but I will. That is the only reason not to give you a 5. Thanks. Leon


Title: excellent
Name: pgill
Date: 4/14/2011 1:12:45 PM
Comment:
Just what I needed, Thanks


Title: Cahnge format
Name: sip
Date: 11/19/2008 9:27:36 AM
Comment:
hi, can someone pls change the format to dd/mm/yy hh:mm. It's over my knowing 10x


Title: Just the date?
Name: Ron Pasch
Date: 8/7/2008 9:59:23 AM
Comment:
Nice expression :) I was wondering what part I need to take out to make it check only the date in dd[-/]mm[-/]yyyy format.


Title: Force 4-digit year
Name: ow
Date: 5/15/2008 8:39:37 AM
Comment:
Great expression. I am new to regular expressions. How do I amend the expression to force years to be entered in full 4-digit format? i.e. 29/05/2008 allowed but 29/05/08 not.


Title: a question on regular expression
Name: jyothi
Date: 3/3/2008 2:17:02 AM
Comment:
i need to select the rows with only 1 from a set column values such as 1|10 11|1 10|1 1|11 please answer me with mysql regexp


Title: re: Different Version
Name: Michael Ash
Date: 6/19/2007 1:08:23 AM
Comment:
The suggested modification doesn't validate the non-match text of 12/31/2003. The other two are not valid in any format. See http://regexadvice.com/blogs/mash/archive/2004/06/17/309.aspx for alternate formats.


Title: re: using Regexp with SQL
Name: Michael Ash
Date: 6/19/2007 1:01:44 AM
Comment:
Vibhuti, SQL doesn't support all the features this regex uses, so you can't use it on that platform. The more advanced grouping features don't seem to be supported. You can try modifying http://regexlib.com/REDetails.aspx?regexp_id=151 but the non capturing group may need to be removed and if so the back references changed.


Title: Different Version
Name: Bobby D.
Date: 6/18/2007 3:49:18 PM
Comment:
Here a version that supports the "non-matching text" above: ^(?=\d)(?:(?:1[012]|0?[1-9])([-./])(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$


Title: using Regexp with sql
Name: Vibhuti Devatraj
Date: 4/5/2007 11:10:54 AM
Comment:
Hi Ash im trying to use the regular expression given by you in my Sql code which is like select 1 from dual where regexp_like( '31/12/2003 11:59:59 PM','^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$') But this always returns null, though the format is right. Thanks in advance Regards Vibhuti


Title: using Regexp with sql
Name: Vibhuti Devatraj
Date: 4/5/2007 11:10:08 AM
Comment:
Hi Ash im trying to use the regular expression given by you in my Sql code which is like select 1 from dual where regexp_like( '31/12/2003 11:59:59 PM','^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$') But this always returns null, though the format is right. Thanks in advance Regards Vibhuti


Title: Need another format
Name: star Scaria
Date: 3/1/2007 11:44:15 PM
Comment:
I am new to this regular expression.i want a regular expression for this date format mm/dd/yyyy hh:MM:ss AM/PM. Can u plz help me to find out solution


Title: Changes Needed
Name: Chris
Date: 10/19/2006 6:55:07 AM
Comment:
I really like your expression that you developed. I would really like to use it except 12/22/2003 doesn't fit this expression. Is there a way to have two separate expressions: one for US and the other for EUR. Thanks...


Title: regex for 08/Sep/2006:16:13:49
Name: sabby
Date: 9/21/2006 7:55:06 AM
Comment:
i need a regex for the form 08/Sep/2006:16:13:49


Title: Re: Can I give range for year from 1900 to 9999
Name: Michael Ash
Date: 2/2/2006 2:59:32 PM
Comment:
Change all [6-9] to just 9


Title: Can I give range for year from 1900 to 9999
Name: Michael Ash
Date: 1/31/2006 8:12:44 AM
Comment:
Thank you so much again,but still I have one dought.how can I limit the range of year in 'yyyy' fromat.eg. if I want to give range between 1900 - 9999 how can i do it?


Title: Re: Can I use ' / ' only as a date seperator ?
Name: Michael Ash
Date: 1/25/2006 2:22:34 PM
Comment:
Replace [-./] with \/


Title: Can I use ' / ' only as a date seperator ?
Name: Michael Ash
Date: 1/25/2006 5:10:58 AM
Comment:
thank you very much for replying.It really help me a lot.I have still one more problem.Can i use only '/'as a date seperator.If so than please reply me soon.I am new to world of regular expression.


Title: Re: Can I use year in 'yyyy' format only..it's very urgent!!
Name: Michael Ash
Date: 1/24/2006 10:39:36 AM
Comment:
Remove the question mark after (?:1[6-9]|[2-9]\d) This occurs in two places.


Title: Can I use year in 'yyyy' format only..it's very urgent!!
Name: Michael Ash
Date: 1/24/2006 6:47:59 AM
Comment:
Hi Michael !!! I am really happy with your regular exp provided for checking date/time format.But I want to use the year part in only 'yyyy' format only.Can you suggest me the solution?? It's really very urgent.


Title: Re: removal of am/pm
Name: Michael Ash
Date: 6/8/2005 11:36:54 AM
Comment:
I'm not clear on what you want. Do you want to remove AM/PM altogether or just make that part optional? If it is the latter, putting a question mark after the parenthises that contain the A,P and M characters in the expression would make that part optional


Title: removal of am/pm
Name: sat
Date: 6/8/2005 8:40:09 AM
Comment:
Hi, In the time part of regular expression can we the option of am/pm.If s how & wat should I remove?


Title: Can you please elaborate
Name: Darren Neimke
Date: 4/24/2005 5:57:26 PM
Comment:
Hi Michael, I just saw your comment: >> There seems to be a problem with the test page on this site. Can you please elaborate on that because, I'm not currently aware of any specific issues with the testing tool. Thanks, - Darren


Title: It works !
Name: damber
Date: 4/22/2005 7:16:25 PM
Comment:
Thanks Michael - it was the unescaped / that was causing the issue - I initially had it as /regexp/ but it resulting in page errors on loading (I assume due to this unescaped /) hence the alternative style - I've now put it back to this format. Anyway, it works now, thanks for your help - and for the excellent expression.


Title: Re: Does it really work ???
Name: Michael Ash
Date: 4/21/2005 11:23:38 AM
Comment:
try this declaration var re = /^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-.\/])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/; note the foward slash in the pattern has been escaped


Title: Re: Does it really work ???
Name: Michael Ash
Date: 4/21/2005 11:03:29 AM
Comment:
Also you should use the var re = /pattern/ syntax so you don'have to escape the backslashes You'll still need to escape the forward slash within the pattern.


Title: Re: Does it really work ???
Name: Michael Ash
Date: 4/21/2005 10:29:43 AM
Comment:
The pattern is correct. There seems to be a problem with the test page on this site. As far as your javascript you need to escape the forward slash in the pattern. Change the part of the pattern from [-./] to [-.\/] You can use these pages to test it http://www.fileformat.info/tool/regex.htm or http://www.unusualresearch.com/regex/toolrei.htm


Title: Does it really work ???
Name: damber
Date: 4/20/2005 4:30:19 PM
Comment:
I've tried this in Javascript: var dateRE = new RegExp('^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$'); return (dateRE.test(sDate)); And it always returns false...? e.g.: 10/02/2005 or 10/02/2005 10:12:11 PM Apologies if this is just my lack of understanding. I've tested this in FireFox 1.01 and IE 6.0 - can you please post the code you have used to get this to work ?


Title: Re: Re: Leap Year doesn't work
Name: JaxFL
Date: 6/4/2004 12:30:08 PM
Comment:
I'm new to the world Regular Expressions, so forgive my previous error. I tried a few other simple validators using the Expression Tester on this site and they failed as well. ??? When I use your expression in .Net, it works fine, including 2/29/04. Thanks!


Title: Re: Leap Year doesn't work
Name: Michael Ash
Date: 6/4/2004 11:05:21 AM
Comment:
Refer to the descpition for the format being validated. Both of those values are invalid for the format being checked. Please refer to http://blogs.regexadvice.com/mash/archive/2004/04/23/1021.aspx in you need another format.


Title: Leap Year doesn't work
Name: JaxFL
Date: 6/4/2004 10:37:10 AM
Comment:
2/29/04, 2/29/2004 both failed.


Title: JScript/Javascript safe
Name: Michael Ash
Date: 3/4/2004 1:18:28 PM
Comment:
In dabbling with ASP.net it came to my attention that some of the expressions on this libriary, included some of my own, won't work for client-side validations using javascript/jscript because JScript only supports a sub-set of the regular expression syntax that VB.net and VBScript support. This version should work fine both client and server side.


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