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
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
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.