Time regular expression

  • 14 March 2019
  • 2 replies
  • 2 views

Badge +2

Good evening,

 

I single line of text field that I'm using for users to enter in a time. I'm validating the field using this regular expression: ^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$

 

It works fine for putting in a time of, for example, 1:30 however I am wondering if there is a way to allow the user (or better yet force the user) to add AM or PM after the time.

 

All help is appreciated.

Andrew


2 replies

Userlevel 5
Badge +14

sure, something like this shouldw work

 

^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]s(AM|PM)$

 

                  

 

 

 

Badge +2

Thanks @emha. It works perfectly.

Reply