天天看点

js移动手机号码验证

//验证手机号码是否合法

String username = mobile.trim(); //将号码前后的空格去掉

//只能输入数字且是11位号码

Matcher matcher = Pattern.compile("^((134|135|136|137|138|139|150|151|152|157|158|159|147|182|183|184|187|188)\\d{8})$").matcher(mobile);

if(!matcher.matches()){

alert("你的输入有误!");

}

完整的移动电话号码验证代码:

$(document).ready(function(){

//激发input的change事件

$("#mobile").change(function(){

//将号码前后的空格去掉

var mobile = $("#mobile").val().trim();

//只能输入数字且是11位号码

reg = /^((134|135|136|137|138|139|150|151|152|157|158|159|147|182|183|184|187|188)\d{8})$/;

if(!reg.test(mobile)){

alert("你的输入有误!");

}

});

});

继续阅读