Title |
Test
Find
Validate 12hour clock
|
Expression |
(?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?) |
Description |
A co-worker needed a regex to validate time. He could only find patterns that match a 24hour clock. I whipped this expression up to validate a 12hour clock. Hope somebody finds it useful. |
Matches |
12:00am | 01:30pm | 4:59 |
Non-Matches |
15:30 | 4:78am | 00:00 |
Author |
Rating:
Ariel Merrell
|
Source |
|
Your Rating |
|
Title: This matches HH:MM
Name: AMErrell
Date: 5/12/2005 6:10:32 PM
Comment:
If you have HH:MM:SS it will only match the HH:MM.
This was not made to capture the seconds. Only to catch entries with 16:03 or 4:59pm. 4:59 will return a match but as I said it is validating HH:MM so if you had 45:59 will not match since it's obviously MM:SS.
Title: No MAtch MM:SS
Name: Jhon
Date: 5/12/2005 5:47:55 PM
Comment:
De format MM:SS like 4:59 don't match
Title: Reg Ex
Name: CJ
Date: 1/31/2005 7:17:20 PM
Comment:
Yeah. I found it very useful. Much appreciated dude, let me know if I can attempt to be of service in anyway.
-CJ