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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find yyyy/mm/dd hhMMss Date
Expression
^(?ni:(?=\d)((?'year'((1[6-9])|([2-9]\d))\d\d)(?'sep'[/.-])(?'month'0?[1-9]|1[012])\2(?'day'((?<!(\2((0?[2469])|11)\2))31)|(?<!\2(0?2)\2)(29|30)|((?<=((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00)\2\3\2)29)|((0?[1-9])|(1\d)|(2[0-8])))(?:(?=\x20\d)\x20|$))?((?<time>((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2}))?)$
Description
YYYY/MM/DD hh:mm:ss format DateTime Regex. This regex will validate a date, time or a datetime. It will also capture the date fields and the time. Dates are in the YYYY/MM/DD format and validated for months, number of days in a month and leap years (29/2) Date field can be separated by matched periods(.), dashes(-) or forward slashes(/) Time is either 12 hour AM/PM format (hh:mm:ss AM), where minutes and seconds are optional. AM or PM required. or 24 hour military format (hh:mm:ss), from 00:00:00 to 23:59:59, where hours and minutes fields are required, including leading 0 for hours less than 10. Please refer to http://blogs.regexadvice.com/mash/archive/2004/04/23/1021.aspx for additional info Datetime is the above date and time formats separated by a space, with the date first (YYYY/MM/DD hh:mm:ss) !IMPORTANT NOTE: your regex engine must support lookbehinds and named groups to use this expression
Matches
12:30 PM | 2004-02-29 | 2004/3/31 02:31:35 AM
Non-Matches
2:00 | 2200.2.29 | 0000/00/00 00:00:00 AM
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: Excellent
Name: Developer
Date: 9/12/2012 1:33:06 PM
Comment:
This is fantastic. I was wondering whether it would be possible to check just for datetime (YYYY/MM/DD hh:mm:ss) and without date, and time. Do you mind posting separate expressions for these? Thanks!


Title: Excellent
Name: Developer
Date: 9/12/2012 11:56:31 AM
Comment:
This is fantastic. I was wondering whether it would be possible to check just for datetime (YYYY/MM/DD hh:mm:ss) and without date, and time. Do you mind posting separate expressions for these? Thanks!


Title: Excellent
Name: Developer
Date: 9/12/2012 11:56:23 AM
Comment:
This is fantastic. I was wondering whether it would be possible to check just for datetime (YYYY/MM/DD hh:mm:ss) and without date, and time. Do you mind posting separate expressions for these? Thanks!


Title: A
Name: B
Date: 2/3/2006 3:13:16 PM
Comment:
12:12 AM


Title: Thanks
Name: b3b4
Date: 6/30/2004 7:54:21 AM
Comment:
it's just the answer to my question,thanks!


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