Regular Expression To Match 12-hour Time With AM/PM

A regular expression to match a 12-hour time with AM/PM after it.

/^ *(1[0-2]|[1-9]):[0-5][0-9] *(a|p|A|P)(m|M) *$/

Matches:

  • 1:00 PM
  • 1:00 pm
  • 12:59am

Non-matches:

  • 13:00 PM
  • 1:00
  • 12:59

See Also: