"Yared Hufkens" <y423d@xxxxxxxx> wrote in message news:4FB5667D.7020801@xxxxxxxx... > Try this: > /(0?[1-9]|[12][0-9]):?[0-5][0-9]/ > > FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] > to [12]). > > > Am 17.05.2012 22:37, schrieb Jim Giner: >> ok - finally had to come up with my own regexp - and am failing. >> >> 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? >> >> >> Nope - that didn't work. Tested it against 1900, 1300 and 13:00 and all came thru as OK. Also - I don't understand at all the following: > FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] > to [12]). I know (?) that [1-9] validates any digit from 1 to 9 - I was already using that. And your point about [1-2] doesn't make sense to me since I need to validate 10:00 which [1-2] in my usage would cause 10:00 to fail. And I don't know what ? means at all. FWIW - I couldn't find much in the way of tutorials on the meanings of the various chars in regexp's. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php