Time - regular expressions

It should check if the time is valid or not.

It should accept:

xx:xx AM
x:x AM
xx:xx PM
x:x PM

  $txt='8:30 AM';

  if (preg_match("/(\\\\d+)(:)(\\\\d+)(\\\\s+)(PM|AM)/", $txt))
	  echo "passed";
  else {
	  echo "FAIL!";

What is wrong?

Is "[font=monospace]99:99

                         PM[/font]" valid?

Thank you, working great.

I really have to learn regular expressions properly again, which site do you recommend?


I tested it, it work ok but

8:30 PM - passed
8:30 PMf - passed (Should be FAIL)
f8:30 PM - passed (Should be FAIL)

Try that…

Add ^ after the first / and $ before the last /