Skip to main content
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 PatternName / ComponentFunction & Rule
[01]\d|2[0-3]Hours00 to 23.
:[0-5]\dMinutes00 to 59.
(?::[0-5]\d)?Optional SecondsOptional 00 to 59.

Frequently Asked Questions

How to require seconds?
Remove the `?` after `(?::[0-5]\d)`.
Browse All 40 Patterns