直接上代码
input失去焦点时验证是否为手机号码,如果不是就限制光标在input内
$("#field9").blur(function () {
phone = this.value;
RegCellPhone = /^(1)([0-9]{10})?$/;
falg=phone.search(RegCellPhone);
if (falg==-1){
alert("手机号不合法!");
this.focus();
}
});
上面的例子input的id为field9