splitforms.com

Free tool - runs in your browser

Time regex tester

The time regex tool validates whether a clock time is written in a valid 24-hour, 12-hour AM/PM or ISO 8601 format. Test 24-hour HH:MM and HH:MM:SS, 12-hour h:mm AM/PM, optional leading zeros and ISO 8601 time with fractional seconds and offsets. Pick a preset, edit the regex and paste times one per line. Copy JavaScript, Python or an HTML pattern when you are ready.

Two-digit hours 00-23 and minutes 00-59. No seconds or time zone.

4 of 10 match

  • Match00:00
  • Match07:05
  • Match12:30
  • Match23:59
  • No match24:00
  • No match25:61
  • No match7:5
  • No match7:05
  • No match12:30:00
  • No match12:30 PM

HTML pattern uses the v flag and applies to text inputs, not type=time. Validate again on the server; Python snippets use ASCII matching to keep digit ranges consistent with JavaScript.

24-hour, 12-hour and ISO 8601 time patterns

Hours are limited to 00-23 and minutes and seconds to 00-59 in the 24-hour presets. The 12-hour preset uses 1-12 and requires AM/PM. Default pattern: ^([01]\d|2[0-3]):[0-5]\d$. Every preset below is checked against its match and no-match samples.

PresetRegexMatch / no match examplesNotes
24-hour HH:MM^([01]\d|2[0-3]):[0-5]\d$Match: 00:00, 07:05, 12:30, 23:59
No match: 24:00, 25:61, 7:5, 7:05, 12:30:00, 12:30 PM; empty string
Two-digit hours 00-23 and minutes 00-59. No seconds or time zone.
24-hour with optional seconds^([01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$Match: 00:00, 07:05, 12:30:00, 23:59:59
No match: 24:00, 25:61, 7:5, 12:30:60, 12:30:5, 12:30:00.123; empty string
HH:MM or HH:MM:SS. Seconds, when present, need two digits from 00-59.
24-hour with optional leading zero^([01]?\d|2[0-3]):[0-5]\d$Match: 0:00, 7:05, 07:05, 19:30, 23:59
No match: 24:00, 25:61, 7:5, 007:05, 12:30:00; empty string
One or two hour digits; minutes still require two digits. Leading zero is optional.
12-hour h:mm AM/PM^(0?[1-9]|1[0-2]):[0-5]\d\s?([AaPp][Mm])$Match: 7:05 AM, 07:05 pm, 12:00AM, 1:30 Pm, 12:59 PM
No match: 00:00 AM, 13:00 PM, 24:00, 25:61, 7:5 AM, 7:05, 7:05 AM; empty string
Hours 1-12 with optional leading zero, required AM/PM in either case, and zero or one whitespace character before it.
ISO 8601 time (extended format)^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)?$Match: 00:00:00, 23:59:59.123456, 07:05:09Z, 12:30:00.5+05:30, 18:00:00-07:00
No match: 24:00:00, 25:61:00, 7:5, 12:30, 12:30:60Z, 12:30:00.Z, 12:30:00+24:00, 12:30:00+05:60; empty string
Extended HH:MM:SS with optional fractional seconds and optional Z or +/-hh:mm offset. This subset excludes 24:00, leap seconds and basic format.
HTML input type=time value^([01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,3})?)?$Match: 00:00, 07:05, 23:59:59, 12:30:00.1, 12:30:00.123
No match: 24:00, 25:61, 7:5, 7:05, 12:30.123, 12:30:00.1234, 12:30Z, 1:30 PM; empty string
HH:MM or HH:MM:SS with optional 1-3 fractional digits after seconds. No AM/PM or time zone. Native min, max and step constraints are separate.

24-hour HH:MM

Regex^([01]\d|2[0-3]):[0-5]\d$

Match00:00, 07:05, 12:30, 23:59

No match24:00, 25:61, 7:5, 7:05, 12:30:00, 12:30 PM; empty string

NotesTwo-digit hours 00-23 and minutes 00-59. No seconds or time zone.

24-hour with optional seconds

Regex^([01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$

Match00:00, 07:05, 12:30:00, 23:59:59

No match24:00, 25:61, 7:5, 12:30:60, 12:30:5, 12:30:00.123; empty string

NotesHH:MM or HH:MM:SS. Seconds, when present, need two digits from 00-59.

24-hour with optional leading zero

Regex^([01]?\d|2[0-3]):[0-5]\d$

Match0:00, 7:05, 07:05, 19:30, 23:59

No match24:00, 25:61, 7:5, 007:05, 12:30:00; empty string

NotesOne or two hour digits; minutes still require two digits. Leading zero is optional.

12-hour h:mm AM/PM

Regex^(0?[1-9]|1[0-2]):[0-5]\d\s?([AaPp][Mm])$

Match7:05 AM, 07:05 pm, 12:00AM, 1:30 Pm, 12:59 PM

No match00:00 AM, 13:00 PM, 24:00, 25:61, 7:5 AM, 7:05, 7:05 AM; empty string

NotesHours 1-12 with optional leading zero, required AM/PM in either case, and zero or one whitespace character before it.

ISO 8601 time (extended format)

Regex^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)?$

Match00:00:00, 23:59:59.123456, 07:05:09Z, 12:30:00.5+05:30, 18:00:00-07:00

No match24:00:00, 25:61:00, 7:5, 12:30, 12:30:60Z, 12:30:00.Z, 12:30:00+24:00, 12:30:00+05:60; empty string

NotesExtended HH:MM:SS with optional fractional seconds and optional Z or +/-hh:mm offset. This subset excludes 24:00, leap seconds and basic format.

HTML input type=time value

Regex^([01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,3})?)?$

Match00:00, 07:05, 23:59:59, 12:30:00.1, 12:30:00.123

No match24:00, 25:61, 7:5, 7:05, 12:30.123, 12:30:00.1234, 12:30Z, 1:30 PM; empty string

NotesHH:MM or HH:MM:SS with optional 1-3 fractional digits after seconds. No AM/PM or time zone. Native min, max and step constraints are separate.

Regex vs HTML input type=time

time.html

<label for="time-text">Time (HH:MM)</label>
<input id="time-text" name="time" type="text" pattern="([01]\d|2[0-3]):[0-5]\d" title="24-hour time, for example 07:05" required>

<label for="time-native">Local time</label>
<input id="time-native" name="local_time" type="time" step="0.001" required>

A text input can enforce a custom format with the pattern attribute. HTML anchors the entire value and uses the v flag. Add required to reject an empty value. A native input type=time ignores pattern: it validates a local clock value using min, max and step. Its default step is 60 seconds; step=1 allows seconds and step=0.001 allows milliseconds. To check these rules together with required, min, max and pattern in one place, use the HTML form validation tester.

Time zones and server validation

The ISO preset covers extended time-only strings such as 12:30:00.5Z and 12:30:00+05:30. It requires seconds and accepts optional fractions and an optional offset. It excludes dates, named zones, leap seconds and 24:00. An offset gives a UTC difference, not daylight saving rules. Use a date and a time zone with a date-time parser when you need an instant, and validate all submitted values on the server. For the date portion, try the date regex tester.

Time regex FAQ

Why does 24:00 fail the time regex?

These presets restrict hours to 00-23 and minutes and seconds to 00-59. Midnight is 00:00. Some ISO 8601 contexts allow 24:00 as the end of a day, but this tester deliberately uses a narrower range compatible with HTML time values. It also rejects 25:61 and leap seconds.

How do I match 12-hour time with AM/PM?

Choose the 12-hour preset. It accepts 7:05 AM, 07:05 pm and 12:00AM, with an optional leading zero and zero or one whitespace character before AM/PM. Hours must be 1-12, so 00:00 AM and 13:00 PM fail.

Should I use regex or input type=time?

Use input type=time for a native local-time picker. Its value uses 24-hour HH:MM or HH:MM:SS with optional fractional seconds, regardless of the displayed locale. The pattern attribute does not apply to type=time; use min, max and step instead. Use a text input with pattern when you need AM/PM or a custom text format. Validate again on the server.

Does the ISO time regex validate time zones?

The ISO preset accepts an optional Z for UTC or a numeric offset such as +05:30 or -07:00 after required seconds. It checks offset syntax and digit ranges, not named zones such as America/Denver, daylight saving rules or whether an offset is used in a real region. A time without an offset is a local clock reading, not a unique instant.

Can fractional seconds be used in an HTML time value?

Yes. The HTML preset accepts one to three decimal digits after seconds, such as 12:30:00.123. Use step=0.001 for millisecond precision in a native input; the default step is 60 seconds. The ISO preset allows any positive number of fractional digits.