1

I tried with the following regular expression but it is not working as expected.

/^([01]?[0-9]|2[0-3]):[0-5][0-9]{2}(AM|PM)/
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197

3 Answers3

1

You can try using this regex:

^(0?[1-9]|1[012])(:[0-5]\d) [APap][mM]$

REGEX DEMO

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

You can try like this

/^[1-12]:[0-59](A|P)M$/i
Man Programmer
  • 5,300
  • 2
  • 21
  • 21
0

You are missing space before AM|PM and there is unnecessary {2} The following changes works for me:

^([01]?[0-9]|2[0-3]):[0-5][0-9] (AM|PM)

On the string

09:15 AM
Igal S.
  • 13,146
  • 5
  • 30
  • 48