Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
(?:^$)|(?:^([0-9]|0[1-9]|1[0-9]|2[0-4])(:|\.)[0-5][0-9]$)|(?:^([1-9]|0[1-9]|1[0-2])(:|\.)[0-5][0-9] (A|a|P|p)(M|m)$)
/

Description

This regex can be used within a HTML5 input tag to ensure a time has been entered correctly such as 23:40 or 11:40 PM.

Submitted by Scott Mebberson - 10 years ago