[英]Regular Expression match letters and numbers together with javascript
Html input has to validate the below type of strings. Html 输入必须验证以下类型的字符串。 Total length should be 9. and first 3 letters are ABC and it want change.
总长度应该是 9. 前 3 个字母是 ABC 并且它想要改变。 reset of 6 are numbers.
重置为 6 是数字。
Sample Strings : ABC000123
, ABC000001
, ABC004000
示例字符串:
ABC000123
、 ABC000001
、 ABC004000
ABC letters not change (Static) and other six numbers should have 0-9 values with leading zeros. ABC 字母不变(静态),其他六个数字应为 0-9 值,前导零。
Example : UX143ABC000001 <-wrong示例:UX143ABC000001 <-错误
Example : ABC000001 <-correct示例:ABC000001 <-正确
My Frist expression : /^(ABC){1}[0-9]{6,6}$/g
Second Expression : /^(ABC){1}\\d{6}$/g
我的第一个表达式:
/^(ABC){1}[0-9]{6,6}$/g
第二个表达式: /^(ABC){1}\\d{6}$/g
$('#smarttag_pp_ex').keyup(function(e) {
var txt = $(this).val().toUpperCase();
var txt_ = new RegExp('^ABC[0-9]{6,6}');
if(txt_.test(txt)) {
console.log(true);
}else{
console.log(false);
}
});
Regex : ^ABC\\d{6}$
正则表达式:
^ABC\\d{6}$
If you want to restrict 6th digit being 0 (zero) use: ^ABC(?!0{6})\\d{6}$
如果您想限制第 6 位为 0(零),请使用:
^ABC(?!0{6})\\d{6}$
Details :详情:
^
Asserts position at start of a line ^
断言行首的位置(?!)
Negative Lookahead (?!)
负前瞻{n}
Matches exactly n
times {n}
正好匹配n
次\\d
Matches a digit (equal to [0-9]
) \\d
匹配一个数字(等于[0-9]
)$
Asserts position at the end of a line $
断言行尾的位置 <form action="#"> <input pattern="^ABC(?!0{6})\\d{6}$" required > <input type="submit" value="submit"/> </form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.