Jim L. I did't actually consider that wide range of time values. Here
is an update. Still this can be written without help of regex. I must
add one more thing that a '00:01' is invalid in 12 hour format. OP
wants it to be 12-hour format.
function valid_time($time){
$m = substr($time, -2)
On 5/17/2012 9:52 PM, Jim Lucas wrote:
How about this instead?
\d{1,2}):?(?P\d{2})$#', $time, $m);
if (
$m &&
( 0 <= (int) $m['hour'] && 12 >= (int) $m['hour'] ) &&
( 0 <= (int) $m['minute'] && 59 >= (int) $m['minute'] )
) {
return TRUE;
}
return false;
}
Let me know.
I optimized it a li
On 5/17/2012 8:07 PM, Jim Giner wrote:
"Jim Lucas" wrote in message
news:4fb5b89e.8050...@cmsws.com...
On 5/17/2012 1:57 PM, shiplu wrote:
On Fri, May 18, 2012 at 2:37 AM, Jim
Ginerwrote:
ok - finally had to come up with my own regexp - and am failing.
Trying to validate an input of a time
"Jim Lucas" wrote in message
news:4fb5b89e.8050...@cmsws.com...
> On 5/17/2012 1:57 PM, shiplu wrote:
>> On Fri, May 18, 2012 at 2:37 AM, Jim
>> Ginerwrote:
>>
>>> 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
On 5/17/2012 1:57 PM, shiplu wrote:
On Fri, May 18, 2012 at 2:37 AM, Jim Ginerwrote:
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 h
Thank you !
"Govinda" wrote in message
news:3e5dce87-29c1-4679-ad3a-53326435f...@gmail.com...
>
> FWIW - I couldn't find much in the way of tutorials on the meanings of the
> various chars in regexp's.
this helps alot:
http://www.gskinner.com/RegExr/
you can paste your pattern (needle) in the
>
> FWIW - I couldn't find much in the way of tutorials on the meanings of the
> various chars in regexp's.
this helps alot:
http://www.gskinner.com/RegExr/
you can paste your pattern (needle) in the top input, and hover over each char
to see what it means in grep land.
Paste your haystack
"Yared Hufkens" wrote in message
news:4fb5667d.7020...@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 regex
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 h
On Fri, May 18, 2012 at 2:37 AM, Jim Giner wrote:
> 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 prob
OOPS
FORGOT to mention that I modify the string to add a colon if it is entered
without one, so my regexp
always expects a ":" to be in the middle. So in actuality - my regexp is
'passing' a value of 13:00 as legitimate, when it should not be.
--
PHP General Mailing List (http://www.php.net/
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
12 matches
Mail list logo