T
ToolPrime

Regex for Time (HH:MM:SS)

Validates 24-hour time format with valid ranges.

Pattern

/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/

Live Tester

Enter a string to test

Examples

00:00:00
12:30:45
23:59:59
24:00:00
12:60:00
1:30:00

Pattern Breakdown

^([01]\d|2[0-3]) — hour 00-23

:[0-5]\d — minutes 00-59

:[0-5]\d$ — seconds 00-59

Code Snippets

Javascript

const regex = /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;
regex.test("12:30:45"); // true

Python

import re
pattern = r"^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$"
bool(re.match(pattern, "12:30:45"))  # True

Php

$pattern = '/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/';
preg_match($pattern, "12:30:45"); // 1

Related Patterns

Frequently Asked Questions

What is the regex for Time (HH:MM:SS)?
The regex pattern for Time (HH:MM:SS) is /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/. Validates 24-hour time format with valid ranges.
How do I use the Time (HH:MM:SS) regex in JavaScript?
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the Time (HH:MM:SS) pattern match?
It matches strings like 00:00:00; it rejects strings like 24:00:00. See the Examples section above for the full list of matching and non-matching cases.

Related Tools