jquery REGEX验证字母和数字onlyu

use*_*178 2 javascript jquery

任何机构都可以告诉我使用我的文本框的正则表达式验证应该只采用字母和数字吗?

  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)

我正在使用这个,但它不起作用.任何人都可以告诉我

谢谢

set*_*ler 5

.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)