以 hh:mm am/pm 格式表示时间的正则表达式 [英] Regex for time in hh:mm am/pm format
本文介绍了以 hh:mm am/pm 格式表示时间的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要对学校项目的输入进行严格验证,时间格式为 HH:MM am/pm.到目前为止,我已经有了这个 RegEx 表达式:
I need to make strict validation of input for a school project, time in format HH:MM am/pm. So far i've got this RegEx expression:
(([01]?[0-9]):([0-5][0-9]) ([AaPp][Mm]))
这是一个工作演示:http://regexr.com/3c9b5
唯一的问题是它接受 13:00 到 19:59 的时间
The only problem is that it accepts times 13:00 to 19:59
正确的正则表达式是什么?RegEx 一直对我来说很难
What is the correct regular expresion? RegEx has always been hard for me
推荐答案
您可以使用:
\b((1[0-2]|0?[1-9]):([0-5][0-9]) ([AaPp][Mm]))
EDIT: ^ changed this from "0" to "1" to not accept 00:00
这篇关于以 hh:mm am/pm 格式表示时间的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文