Regex for 24-Hour Time
Regex Pattern
^([01]\d|2[0-3]):([0-5]\d)$24-hour clock time in HH:MM format
Quick Answer
The regex pattern for 24-hour time is `^([01]\d|2[0-3]):([0-5]\d)$`. 24-hour clock time in HH:MM format. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 00:00 | ✓ Matches |
| 23:59 | ✓ Matches |
| 14:30 | ✓ Matches |
| 08:15 | ✓ Matches |
| 24:00 | ✗ No match |
| 12:60 | ✗ No match |
| 2:30 | ✗ No match |
| 14-30 | ✗ No match |
Code Examples
javascript
const regex = /^([01]\d|2[0-3]):([0-5]\d)$/; const isValid = regex.test(value);
python
import re
pattern = r'^([01]\d|2[0-3]):([0-5]\d)$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^([01]\d|2[0-3]):([0-5]\d)$/ if value =~ pattern puts "valid" end
php
if (preg_match('/^([01]\d|2[0-3]):([0-5]\d)$/', $value)) {
echo "valid";
}java
String pattern = "^([01]\\d|2[0-3]):([0-5]\\d)$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
Date YYYY-MM-DD
ISO 8601 date format
Date DD/MM/YYYY
European date format with slashes
12-Hour Time with AM/PM
12-hour clock with AM/PM
Email Address
Validates a standard email address format
Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits
URL (HTTP/HTTPS)
Validates HTTP and HTTPS URLs