Re: regexp novice
| From: | Jim Giner | Date: | Thu, 17 May 2012 21:07:34 +0000 |
| Subject: | Re: regexp novice | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-317884@lists.php.net to get a copy of this message | ||
"Yared Hufkens" <y423d@yahoo.de> wrote in message
news:4FB5667D.7020801@yahoo.de...
> 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.