ereg / preg_match time validation
Hi, I want to validate the time the user has entered to see whether it's in the correct format (12 hour format).
From googling around I found:
PHP Code:
# Returns time in HH:MM[AM|PM] format if it matches, else false
function checkTime($time)
{
return (preg_match('/[\s0]*(\d|1[0-2]):(\d{2})\s*([AaPp][Mm])/xms', $time, $match))
? sprintf('%02d:%d%s', $match[1], $match[2], strtoupper($match[3]))
: false;
}
It almost works, but it allows 21:50pm, I don't have any knowledge of ereg / preg_match so I'm finding it hard to alter it to fix it.
Anyone know what I need to do to fix it? Or come up with a better solution?
Thanks.