Home
TeamSite
regex for hours, minutes
nugget_shark
Guys,
I know that to you Perl regex experts out that this might be easy, but I'm a neophyte...
Would like to know if anyone has a regular expression that would check for valid hours between 1-12 and minutes 0-60...
I currently have
valid_input => '/^[0-1][0-9]/' # for hours
and
valid_input => '/^[0-6][0-9]/', # for minutes
but they're not really sufficiet as I'd still probably need to call a subroutine to check...
Would like to include as part of a a Tag_info, valid_input expression...
Thanks,
Doug
Find more posts tagged with
Comments
jbonifaci
The below regex will only allow 1, 2, 3, ... 11, 12:
/^((1[0-2])|([1-9]))$/
The below regex will only allow 01, 02, 03, ... 12, 12:
/^((1[0-2])|(0[1-9]))$/
The below regex will only allow 00, 01, 02, ... 58, 59:
/^[0-5][0-9]$/
The below regex will only allow 1:00, 1:01, 1:02, ... 12:58, 12:59:
/^((1[0-2])|([1-9])):[0-5][0-9]$/
The below regex will only allow 01:00, 01:01, 01:02, ... 12:58, 12:59:
/^((1[0-2])|(0[1-9])):[0-5][0-9]$/
~Jeff
nugget_shark
thanks Jeff....
good stuff....
appreciate it!!!
jbonifaci
No problem, glad I could help!
~Jeff