How to validate the time format in the 12 hour format? [closed]

0

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.

    
asked by Moisés Aguilar 21.11.2018 в 02:04
source

1 answer

1

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);
    
answered by 21.11.2018 в 03:54