Regex for AM PM time format for jquery

后端 未结 6 444
耶瑟儿~
耶瑟儿~ 2020-12-09 17:16

I am being frustrated by a regular expression to mask the input field. I want to Limit input to hh:mm AM|PM format and I can\'t get this regex to work.

I use this

6条回答
  •  天命终不由人
    2020-12-09 17:53

    So I'm pretty sure this is solved by now, but I was recently struggling with this and couldn't find an answer fast enough. I'm using Bootstrap Validator (bootstrapvalidator.com by @nghuuphuoc) in conjunction with Eonasdan's DateTimepicker to validate an hour (PS: You can disable the date in Eonasdan's plugin).

    Since Bootstrap Validator doesn't yet have a validator for time, you have to use a Regex. This one worked perfectly for me:

    ^([0-1]?[0-9]|2[0-3]):[0-5][0-9] [APap][mM]$

提交回复
热议问题