国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js結(jié)合正則實現(xiàn)國內(nèi)手機號段校驗

2019-11-20 12:12:55
字體:
供稿:網(wǎng)友

附加一個utils對象,內(nèi)含一個校驗手機號函數(shù),一個格式化返回數(shù)據(jù)函數(shù)

var isChinaMobile = /^134[0-8]/d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[2-478])/d{8}$/; //移動方面最新答復(fù)var isChinaUnion = /^(?:13[0-2]|145|15[56]|176|18[56])/d{8}$/; //向聯(lián)通微博確認并未回復(fù)var isChinaTelcom = /^(?:133|153|177|18[019])/d{8}$/; //1349號段 電信方面沒給出答復(fù),視作不存在var isOtherTelphone  = /^170([059])/d{7}$/;//其他運營商 var utils = {  checkMobile: function(telphone){    telphone = this.trim(telphone);    if(telphone.length !== 11){      return this.setReturnJson(false, '未檢測到正確的手機號碼');    }    else{      if(isChinaMobile.test(telphone)){        return this.setReturnJson(true, '移動', {name: 'ChinaMobile'});      }      else if(isChinaUnion.test(telphone)){        return this.setReturnJson(true, '聯(lián)通', {name: 'ChinaUnion'});      }      else if(isChinaTelcom.test(telphone)){        return this.setReturnJson(true, '電信', {name: 'ChinaTelcom'});      }      else if(isOtherTelphone.test(telphone)){        var num = isOtherTelphone.exec(telphone);        return this.setReturnJson(true, '', {name: ''});      }      else{        return this.setReturnJson(false, '未檢測到正確的手機號碼');      }    }  },  setReturnJson: function(status, msg, data){    if(typeof status !== 'boolean' && typeof status !== 'number'){      status = false;    }    if(typeof msg !== 'string'){      msg = '';    }    return {      'status': status,      'msg': msg,      'data': data    };  }}

驗證130-139,150-159,180-189號碼段的手機號碼

<script type="text/javascript">var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+/d{8})$/; if(!myreg.test($("#phone").val())) {   alert('請輸入有效的手機號碼!');   return false; } </script>

以上代碼是在jquery下調(diào)試的。

不需要jquery的代碼

function validatemobile(mobile)   {     if(mobile.length==0)     {      alert('請輸入手機號碼!');      document.form1.mobile.focus();      return false;     }       if(mobile.length!=11)     {       alert('請輸入有效的手機號碼!');       document.form1.mobile.focus();       return false;     }         var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+/d{8})$/;     if(!myreg.test(mobile))     {       alert('請輸入有效的手機號碼!');       document.form1.mobile.focus();       return false;     }   } 

以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 马鞍山市| 华容县| 天津市| 甘德县| 高陵县| 和龙市| 密山市| 扎兰屯市| 正安县| 乌什县| 定结县| 皋兰县| 沾益县| 永嘉县| 安远县| 建平县| 东乡族自治县| 临夏市| 清远市| 富川| 襄樊市| 社会| 句容市| 福州市| 宁津县| 洪雅县| 梓潼县| 革吉县| 邵阳县| 志丹县| 博野县| 苏尼特右旗| 岚皋县| 嘉鱼县| 枣阳市| 天峨县| 北流市| 天峨县| 怀化市| 简阳市| 炎陵县|