Regex tester / pattern library
Regex: time (24-hour hh:mm)
/^([01]\d|2[0-3]):[0-5]\d$/ Test it live How it works
Hours 00–23 ([01]\d covers 00–19, 2[0-3] covers 20–23), minutes 00–59. Append (:[0-5]\d)? for optional seconds.
Honest caveats
Requires the leading zero — 9:30 fails, 09:30 passes. Relax with ^([01]?\d|2[0-3]) if bare single digits should pass.
Matches
09:3023:5900:00
Doesn't match
24:0012:609:30