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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

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: The rating for this expression. Ariel Merrell
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: 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


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