On 2012-05-17 22:37, Jim Giner wrote:
Trying to validate an input of a time value in the format hh:mm, wherein
I'll accept anything like the following:
hmm
hhmm
h:mm
hh:mm
in a 12 hour format. My problem is my test is ok'ing an input of 1300.
Here is my test:
if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t))
return true;
else
return false;
Can someone help me correct my regexp?
/([0][1-9]|[1][0-2]|^[1-9]):[0-5][0-9]/
The third part of your alternate expressions matches "3:00" from the
string "13:00" (it ignores the 1 at the beginning). Using ^ avoids this
because now only one digit is allowed before the :.
Bye, Andreas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php