RegEx - 时间验证((h)h:mm) [英] RegEx - Time Validation ((h)h:mm)
本文介绍了RegEx - 时间验证((h)h:mm)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
/^\d{1,2}[:][0-5][0-9]$/
就是我所拥有的。这将分钟限制在00-59。但是,它不会将时间限制在0到12之间。对于相似性和一致性,如果可能的话,我希望单独使用RegEx。
is what I have. this limits minutes to 00-59. It does not, however, limit hours to between 0 and 12. For similarity and uniformity I would like to do this with RegEx alone if possible.
我还会更多比如第一个数字是可选的。即09:30接受以及9:30。我玩了范围,但超出范围的东西总是可以接受的。
Further-more I would like the first digit to be optional. i.e. 09:30 accepted as well as 9:30. I played around with ranges, but something out of range is always acceptable.
推荐答案
/^(10|11|12|[1-9]):[0-5][0-9]$/
我认为您不希望0:50作为有效时间。
I don't think that you want 0:50 as a valid time either.
这篇关于RegEx - 时间验证((h)h:mm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文