任何机构都可以告诉我使用我的文本框的正则表达式验证应该只采用字母和数字吗?
var BLIDRegExpression = /^[a-zA-Z0-9]*$/;
if (BLIDRegExpression.test(BLIDIdentier)) {
alert('The BLID Identifier may only consist of letters or numbers and must be exactly five characters long.');
return false;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用这个,但它不起作用.任何人都可以告诉我
谢谢
.test如果字符串匹配,则返回true.我想你想要:
var BLIDRegExpression = /^[a-zA-Z0-9]{5}$/; // {5} adds the requirement that the string be 5 chars long
if (!BLIDRegExpression.test(BLIDIdentier)) {
alert('The BLID Identifier may only consist of letters or numbers and must be exactly five characters long.');
return false;
}
Run Code Online (Sandbox Code Playgroud)