Regex for Time (HH:MM, 24-hour)
Matches time in 24-hour format (00:00 to 23:59).
Pattern
/^([01]\d|2[0-3]):([0-5]\d)$/Pattern Breakdown
| Token | Explanation |
|---|---|
| ^ | Start of string |
| ([01]\d|2[0-3]) | Hours: 00-23 |
| : | Colon separator |
| ([0-5]\d) | Minutes: 00-59 |
| $ | End of string |
Test Examples
| Input | Match? |
|---|---|
| 09:30 | Match |
| 23:59 | Match |
| 00:00 | Match |
| 24:00 | No match |
| 9:30 | No match |
Common Use Cases
- Time input validation
- Schedule parsing
- Time tracking forms
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?(AM|PM)$12-hour format with AM/PM
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester