php - How to validate time string in hh:mm using preg match? -


below following possiblities. time 12 hours

 inputs          output should  "05:30"           true "asasds"          false "05:30:sads"      false "adas:05:40"      false "04:30:40"        false 

below code wrote,

 $value = "05:30" ; if(!preg_match("/(1[012]|0[0-9]):([0-5][0-9])/", $value)){     echo "failed"; exit; } echo "passed"; exit; 

but prints passed if give $value = "05:30:asdsa". need output "failed".

use anchors match start , end, e.g.

!preg_match("/^(1[012]|0[0-9]):([0-5][0-9])$/", $value)             //^ see here                   ^ 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -