Debugging Time in PHP -


ok have been through several other q&a sections of site looking information pertaining php validation problem having. trying validate user input time a) in valid given time format, , b) valid time begin with. here code using (including html section of form)

if ($_server["request_method"] == "post") {     if (empty($_post["time"])) {         $timeerror = "current time required";     } else {         $time = test_input($_post["time"]);         if (!preg_match("/(([0-1][0-9])|([2][0-3])):([0-5][0-9])/i", $time)) {             $timeerror = "time must in hh:mm format";         }     } }  <input type="text" size="6" name="time" id="time" title="enter current time" required><?php echo $timeerror; ?><br> 

when input time such 06:30 or 6:30 returns error "time must in hh:mm format". frustrating form supposed being published in 2 weeks , there still lot of these types of debugging issues still need sort out.

you reg-ex wrong.

change reg-ex validate time in hh:mm format:

/^([0-1][0-9]|2[0-3]):[0-5][0-9]$/ 

the ^ states start, , $ states end, "2 digits:2 digits" input accepted. time checking ok.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -