I want to validate a time input (like 10:30 am, 02:30 pm) using preg_match()
preg_match()
I use this,
$pattern = \"/([1-12]):([0-5])([0-9])( )(a
The [...] notation in regexes defines character class: something that's applied to the single character. It's alternation that should be used here instead:
[...]
0[1-9]|1[0-2]
... so the regex in whole would look like this:
/^(?:0[1-9]|1[0-2]):[0-5][0-9] (am|pm|AM|PM)$/