# Regex for 24-Hour Time (HH:MM)

> 24-hour time regex for HH:MM that enforces 00–23 hours and 00–59 minutes, with a seconds variation and a 12-hour AM/PM alternative.

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

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.

## 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 |

## Examples

- ✓ matches: `09:30`
- ✓ matches: `23:59`
- ✓ matches: `00:00`
- ✗ does not match: `24:00`
- ✗ does not match: `9:30`
- ✗ does not match: `12:60`

## 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

## FAQ

### 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

- [Regex for Dates in YYYY-MM-DD Format](https://www.devkult.com/regex/date-yyyy-mm-dd.md)
- [Regex for IPv4 Address Validation](https://www.devkult.com/regex/ipv4.md)
- [Regex for Username Validation](https://www.devkult.com/regex/username.md)

Open the interactive page: https://www.devkult.com/regex/time-24h