[英]How to write regular expression to validate character in special places?
I need to validate time field in the textbox. 我需要验证文本框中的时间字段。 I used this regular expression.
我用了这个正则表达式。
var reg_exp = /^([0-9\:]*)$/;
But it allows add : any place in the text box. 但是它允许添加:在文本框中的任何位置。 How to make it to add : only in the third place of the text.
如何添加:仅在文本的第三位。 Ex: 11* : *34
例如:11 * : * 34
Use 采用
^\d{2}:\d{2}$
instead which matches two digits, then a colon and another two digits. 而是匹配两个数字,然后是一个冒号和另外两个数字。
为了验证时间在00:00
到23:59
您可以使用:
/^(?:[01][0-9]|2[0-3]):(?:[0-5][0-9])$/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.