简体   繁体   English

如何编写正则表达式以验证特殊位置的字符?

[英]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:0023:59您可以使用:

/^(?:[01][0-9]|2[0-3]):(?:[0-5][0-9])$/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在angularjs中验证仅具有特殊字符的正则表达式? - How to validate regular expression having only special character in angularjs? 如何使用正则表达式验证密码是否允许至少4位数字和1个字符而没有特殊字符? - How to validate a password allows at least 4 digits and 1 character without special character using regular expression? 如何编写正则表达式以将4字符串验证为非零二进制数字? - How to write a regular expression to validate a 4 character string as a non-zero binary number? 正则表达式不适用于特殊字符 - Regular expression not working for special character 特殊字符密码的正则表达式 - regular expression for password for special character 如何使用jQuery正则表达式验证字符,数字和特殊字符? - How to validate characters, numbers and special characters using jQuery regular expression? 如何在正则表达式中启用向密码验证添加特殊字符 - How to enable adding special character to the password validation in regular expression 寻找正则表达式以验证密码,长度必须大于8个字符,并且至少包含一个特殊字符 - looking for a regular expression to validate a password, must be greater than 8 characters long and contain at least one special character 正则表达式以验证特殊字符集 - Regular expression to validate set of special characters 在Javascript中使用正则表达式匹配特殊字符“-” - Matching Special character '-' using Regular expression in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM