Title |
Test
Find
mm/dd/yyyy hh:MM DateTime, time obligatory
|
Expression |
(?n:^(?=\d)((?<day>31(?!(.0?[2469]|11))|30(?!.0?2)|29(?(.0?2)(?=.{3,4}(19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00))|0?[1-9]|1\d|2[0-8])(?<sep>[/.-])(?<month>0?[1-9]|1[012])\2(?<year>(19|[2-9]\d)\d{2})(?:(?=\x20\d)\x20|$))?(?<time>([01]\d|2[0-3])(:[0-5]\d){1})$) |
Description |
Based on Michael Ash's expression. This regex will validate only datetime, not only date or only time. Dates are in the DD/MM/YYYY HH:mm 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(/). Year range 1900-9999 Time is in 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. Datetime is the above date and time formats separated by a space, with the date first (DD/MM/YYYY HH:mm) !IMPORTANT NOTE: your regex engine must support lookaheads and named groups to use this expression |
Matches |
1/31/2002 10:59 | 2/29/2004 11:03 |
Non-Matches |
1/32/2002 10:59 | 2/29/2003 11:03 |
Author |
Rating:
Not yet rated.
Wouter Hibma
|
Source |
Wouter Hibma |
Your Rating |
|
Title: Not good
Name: Paracyber
Date: 6/27/2006 5:04:42 AM
Comment:
This Match dd/mm/yyyy hh:MM and not mm/dd/yyyy hh:MM !
Title: Mistitled and not complete
Name: Michael Ash
Date: 6/19/2006 11:10:25 AM
Comment:
The pattern title you've given this regex doesn't match what it does. Pattern title say mm/dd/yyyy description says dd/mm/yyyy. Also if you just copied my description you need more editing. Your description is a little off. Your pattern doesn't allow seconds.