24-hour time regex
Hours 00 to 23 and minutes 00 to 59, zero-padded, with optional seconds. Copy the pattern, with 3 inputs it accepts and 5 it rejects, each checked against it at build time.
Part of developer tools.
^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/Flags: none
Open in the testerWhat the 24-hour time regex accepts and rejects
Each result below is the output of the pattern itself, run on the input when this page was built — not a claim copied next to it. A wrong verdict stops the build.
| Input | Result | Why |
|---|---|---|
| 00:00 | Passes | midnight |
| 09:30 | Passes | a zero-padded hour |
| 23:59:59 | Passes | the last second of the day |
| 24:00 | Fails | hour 24 |
| 9:30 | Fails | hour not zero-padded |
| 12:60 | Fails | minute 60 |
| 12:30 PM | Fails | a 12-hour suffix |
| 23:59:60 | Fails | a leap second |
Limits
- Leap seconds (23:59:60) and the end-of-day 24:00 are both legal in ISO 8601 and both refused here, which is what most forms want.
- Fractional seconds (12:30:15.250) and time-zone offsets are not covered.
Try it on your own input
Open this pattern in the regex tester with every example above on its own line. The link adds the g and m flags so that ^ and $ hold per line and every line is tested: the highlighted lines are the ones marked as passing here. Paste your own data in place of the examples — it is matched in your browser and never uploaded.
Other common regexes
- Email address
- URL
- UUID
- IPv4 address
- Hex color
- ISO 8601 date
- Semantic version
- URL slug
- Phone number (E.164)
- US ZIP code
- MAC address
Or open the regex tester empty and bring your own pattern.