JavaScript的:
script src =“http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”
$(文件) . 就绪(函数()
{
$(函数(){
$( '#custom_Expression') . 按键(功能(E){
var txt = String.fromCharCode(e.which);
console.log(txt':'e.which);
if(!txt.match(/^([a-zA-Z][0-9]){3}$/g))
{
return false;
}
});
});
input type =“text”id =“custom_expression”
1 回答
要允许单个字母后跟单个数字,在
[A-Za-z]
和[0-9]
之后一次或多次不需要+
. 大多数情况下,在验证字符串时必须使用锚点 .^
声称我们刚开始,$
声称我们已经结束了 .+
重复前一个标记一次或多次 .要么
repitition quantifier
{3}
正好重复前一个令牌3次 .