I would like to know how valid it is if the time entered by the user has the correct format and has not entered unwanted characters, thanks in advance.
I would like to know how valid it is if the time entered by the user has the correct format and has not entered unwanted characters, thanks in advance.
you can do it with a regular expression and the preg_match()
function:
12 hour format:
preg_match("/^(?:1[012]|0[0-9]):[0-5][0-9]$/", $hours);
24 hour format:
preg_match("/^(?:2[0-3]|[01][0-9]):[0-5][0-9]$/", $hours);