【转】JS超强判断电话号码

JS超强判断电话号码

<script type="text/javascript">
String.prototype.Trim = function() {
var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);
return (m == null) ? "" : m[1];
}

String.prototype.isMobile = function() {
return (/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(this.Trim()));
}

String.prototype.isTel = function()
{
    //"兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"
    //return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
    return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
}

function chkForm() {
    with(document.form_1){
        if (tel_1.value.isMobile()||tel_1.value.isTel()) {
            tel_1.value = tel_1.value.Trim();
            //alert("您的电话/手机号码是:" + tel.value);
            return true;
        }

     else if(form_1.Name_1.value=="")
    {
     alert("请填写您的姓名");
     return false;
    }

<!------------------------------------------------------------------------------------------------------------------------->

        else {
            alert("请输入正确的手机号码或电话号码");
            tel_1.focus();
            return false;
  
  
   }
    }
}
</script>
                 
                 
                  <form method="post" name="form_1" >
              <table width="288" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="76" align="center" valign="middle">姓名:</td>
                  <td width="109"><span class="from">
                    <input name="Name_1" class="from_bd3" style="" size="15" />
                  </span></td>
                  <td width="81" rowspan="2" align="center" valign="middle"><input type="image" border="0" src="images/wysq.gif" value="#" οnclick="return chkForm()"/></td>
                </tr>
                <tr>
                  <td align="center" valign="middle">手机号:</td>
                  <td><span class="from">
                    <input name="tel_1" type="text" class="from_bd" id="cm_xm2" size="15" />
                  </span></td>
                </tr>
              </table>
          </form>

转载于:https://www.cnblogs.com/xiaolinshushu/archive/2012/11/12/2767035.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值