Re: regexp novice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);
        $h = (explode(':', substr($time, 0, -2)));
        $h = $h[0];
        return (is_numeric($h) && is_numeric($m) && $h>0 && $h<13 &&
$m>=0 && $m<60);
}

See the code in action here http://ideone.com/tSQIb

-- 
Shiplu Mokaddim
Talks: http://shiplu.mokadd.im
Follow: http://twitter.com/shiplu
Innovation distinguishes between follower and leader

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux