admin管理员组文章数量:1318570
Can any body tell me what is the Regex validation to use my textbox should take only letters and Numbers?
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;
}
I am using this one but its not working. can anybody tell me.
Thanks
Can any body tell me what is the Regex validation to use my textbox should take only letters and Numbers?
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;
}
I am using this one but its not working. can anybody tell me.
Thanks
Share Improve this question asked Jan 21, 2012 at 16:32 user957178user957178 6314 gold badges16 silver badges27 bronze badges 2- whats the value for BLIDIdentier? – marcio Commented Jan 21, 2012 at 16:37
- by the way, you can use /^[a-zA-Z0-9]{5}$/ to check that the string is exactly 5 characters long too, if you want (to test the second half of your error message too) – Dexter Commented Jan 21, 2012 at 16:39
2 Answers
Reset to default 5.test
returns true if the string matches. I think you want:
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;
}
Reverse your logic. .test()
returns true when it matches, false when it does not match. You want to execute your if
statement when it does NOT match. If you also want it to be required to be exactly 5 characters long, then you can use {5}
instead of *
in your regex like this:
var BLIDRegExpression = /^[a-zA-Z0-9]{5}$/;
if (!BLIDRegExpression.test(BLIDIdentier)) {
alert('The BLID Identifier may only consist of letters or numbers and must be exactly five characters long.');
return false;
}
本文标签: javascriptjquery REGEX validation for letters and Numbers onlyuStack Overflow
版权声明:本文标题:javascript - jquery REGEX validation for letters and Numbers onlyu - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742047682a2417886.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论