Regex for 24-Hour Time (HH:MM)
Valid 24-hour clock time is hours 00–23 and minutes 00–59, zero-padded. The hour needs two alternatives — 00–19 and 20–23 — because a naive [0-2]\d would accept 29. This is the pattern behind time inputs, cron-adjacent config, and log parsing.
/^([01]\d|2[0-3]):[0-5]\d$/How it works, token by token
| Token | Meaning |
|---|---|
| ^([01]\d | hours 00–19: a 0 or 1, then any digit |
| |2[0-3]) | or hours 20–23 |
| : | the literal colon separator |
| [0-5]\d$ | minutes 00–59, then end of string |
What it matches
09:3023:5900:0024:009:3012:60Try it live
One candidate per line — the m flag makes the ^ and $ anchors apply to each line. Edit anything; it runs in your browser.
Variations
^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$with seconds: HH:MM:SS^(0?[1-9]|1[0-2]):[0-5]\d\s?[APap][Mm]$12-hour clock with AM/PM: 9:30 AM, 12:45pmFrequently asked questions
Why doesn't 24:00 match?
The 24-hour clock runs 00:00 through 23:59; midnight is 00:00, not 24:00. (ISO 8601 briefly allowed 24:00 as end-of-day, but dropped it in the 2019 revision — most parsers reject it.)
How do I accept unpadded hours like 9:30?
Make the leading zero optional: ^(0?\d|1\d|2[0-3]):[0-5]\d$. Zero-padding is worth keeping when the strings will be sorted, since 9:30 sorts after 10:00 as text.
Building something custom? The regex tester gives you live match highlighting for any pattern.