Regex newbie! I would like to validate a time string in the format HH:MM with an optional space and AM or PM suffix.
Example: 10:30 or 10:30 AM will both be valid.
Here's what I have so far which is failing:
$test = '12:34';
if(!preg_match("/^\d{2}:\d{2}?\s(AM|PM)$/", $test))
{
echo "bad format!";
}
In addition, is it possible to validate that the HH or MM values are <= 12 and <=60 respectively within the same regex?
Regards, Ben.