Regular Expressions 101

Community Patterns

<input type="time" /> pattern

1

Regular Expression
ECMAScript (JavaScript)

/
^(0\d|1\d|2[0-4]):(0\d|[1-5]\d)(?::(0\d|[1-5]\d))?(?:.(00\d|0[1-9]\d|[1-9]\d{2}))?$
/
gm

Description

As 'time' input doesn't have a [pattern] attribute, you can check its value with this RegExp.

You must provide hours and minutes. Seconds and milliseconds are optional.

To "activate" seconds on the input, give it the step="" attribute with a number reprensenting the incrementation in seconds.

To "activate" milliseconds on the input, set the step attribute to "0.001"

Submitted by Ann MB - 2 years ago (Last modified 2 years ago)