Regex Pattern Library

Time (HH:MM 24-hour)

Match times in 24-hour HH:MM format with valid hour and minute ranges.

What Is This?

This regex pattern validates time strings in 24-hour HH:MM format. Hours range from 00 to 23 (validated via (?:[01]\d|2[0-3])) and minutes range from 00 to 59 (validated via [0-5]\d). The colon is required as the separator.

How to Use This Pattern

1

Pattern

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

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

Usage

Use this pattern for time input validation in forms, scheduling applications, and log parsers. For 12-hour time with AM/PM, a different pattern is needed. The 24-hour format avoids AM/PM ambiguity and is the international standard for time representation.

Examples

Valid times

Matches: 00:00, 12:30, 23:59, 08:05, 14:00. Non-matches: 24:00, 12:60, 12:00 AM, 12-30, 2:00

Edge cases

Matches: 00:01, 09:09, 22:22. Non-matches: 25:00, 00:99, abc:def, 12:00:00

Related Entries

More from this reference:

Frequently Asked Questions

How do I add optional seconds (HH:MM:SS)?

Extend the pattern to: ^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$. For ISO 8601 duration formats, combine with date patterns for full datetime validation.

Should I store times in 24-hour or 12-hour format?

Store times in 24-hour format (HH:MM or HH:MM:SS) internally and convert to 12-hour with AM/PM for display only. 24-hour format avoids ambiguity and sorts correctly.