Data & Formatting · In-Browser Regular Expression Lab
24-Hour Time Regex — Validate Hours (00-23) and Minutes (00-59)
Matches 24-hour military and standard timestamps in HH:mm or HH:mm:ss format.
Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:14:30
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
14:30 Pass
23:59:59 Pass
00:00:00 Pass
08:15 Pass
Expected Invalid Samples (Must Reject)
24:00 Rejected (Pass)
12:60 Rejected (Pass)
25:10:00 Rejected (Pass)
7:30 Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/;
const text = "14:30";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Guarantees hours do not exceed 23 and minutes/seconds stay within 00-59. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| [01]\d|2[0-3] | Hours | 00 to 23. |
| :[0-5]\d | Minutes | 00 to 59. |
| (?::[0-5]\d)? | Optional Seconds | Optional 00 to 59. |
Frequently Asked Questions
How to require seconds?
Related Regular Expressions
Browse All 40 PatternsData & Formatting
ISO Date (YYYY-MM-DD)
Validates 4-digit year, 2-digit month (01-12), and 2-digit day (01-31) in ISO format.
/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/Test regex
Data & Formatting
ISO 8601 Combined Timestamp
Matches ISO 8601 timestamps like 2026-10-14T22:30:00.000Z or with +/- timezone offsets.
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/Test regex
Data & Formatting
5-Field Cron Expression
Matches standard Unix crontab schedules (minute, hour, day of month, month, day of week).
/^(?:\*(?:\/[0-9]+)?|[0-9,-\/]+)\s+(?:\*(?:\/[0-9]+)?|[0-9,-\/]+)\s+(?:\*(?:\/[0-9]+)?|[0-9,-\/]+)\s+(?:\*(?:\/[0-9]+)?|[0-9,-\/]+|[a-zA-Z]{3})\s+(?:\*(?:\/[0-9]+)?|[0-9,-\/]+|[a-zA-Z]{3})$/Test regex