任何人都可以告诉我什么是使用我的文本框的正则表达式验证应该只包含字母和数字吗?
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;
}
我正在使用这个,但它不起作用。谁能告诉我。
谢谢
最佳答案
.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;
}
关于javascript - 仅对字母和数字进行 jquery REGEX 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8954637/