电话,手机号码的简单验证

js如下:
/* 除空格 */
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}

/*电话验证*/
String.prototype.isTel = function() {
return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(this.trim()));
}

/*手机号验证*/
String.prototype.isMobile = function() {
return (/^(((13[0-9]{1})|15[0189])+\d{8})$/.test(this.trim()));
}

function validateForm(thisform){
var phoneNumber = thisform.phoneNumber.value = thisform.phoneNumber.value.trim();
if(phoneNumber.length > 0){
if(!phoneNumber.isMobile() && !phoneNumber.isTel()){
alert("请输入正确的手机号码或电话号码!如:13888888888或010-8888888");
thisform.phoneNumber.focus();
return false;
}
}

}

你可能感兴趣的:(javaScript)