devkult_
tools26converters34
home/regex/time-24h

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

TokenMeaning
^([01]\dhours 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:30
23:59
00:00
24:00
9:30
12:60

Try 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:45pm

Frequently 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.

Related patterns

Building something custom? The regex tester gives you live match highlighting for any pattern.