求电话的正则验证表达式,电话包括座机号和手机号,座机号可以有区号和分机号

2024-11-29 06:30:42
推荐回答(1个)
回答1:

//判断手机是否正确
function isnum1(id) {
var str = document.getElementById(id).value;
if (str != "" && str != null) {
var zz = /^13[0-9]{1}[0-9]{8}$|^15[0-9]{1}[0-9]{8}$|^18[8-9]{1}[0-9]{8}$/;
if (!str.match(zz)) {
alert("手机格式不正确!");
document.getElementById(id).value = "";
var txt = document.getElementById(id);
txt.focus();
}
}
}

//判断电话是否正确
function isnum2(id) {
var str = document.getElementById(id).value;
if (str != "" && str != null) {
var zz = /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/;
if (!str.match(zz)) {
alert("电话格式不正确!");
document.getElementById(id).value = "";
var txt = document.getElementById(id);
txt.focus();
}
}
}