js判斷手機號電訊廠商的方法,js手機號電訊廠商

來源:互聯網
上載者:User

js判斷手機號電訊廠商的方法,js手機號電訊廠商

本文執行個體講述了js判斷手機號電訊廠商的方法。分享給大家供大家參考。具體如下:

在做WEB項目時,有時候需要根據使用者的輸入手機號碼判斷該號的電訊廠商是移動、聯通、電信或其他,再根據不同的電訊廠商做出相應的處理,下面介紹js中如何判斷手機號的電訊廠商的代碼。
js實現方法:

var isChinaMobile = /^134[0-8]\\d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[2-478])\\d{8}$/; //移動方面最新回覆var isChinaUnion = /^(?:13[0-2]|145|15[56]|176|18[56])\\d{8}$/; //向聯通微博確認並未回複var isChinaTelcom = /^(?:133|153|177|18[019])\\d{8}$/; //1349號段 電信方面沒給出回覆,視作不存在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, '聯通', {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    };  }}

希望本文所述對大家的javascript程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.