國內手機號段校驗正則表達式
國內手機號段校驗正則
附加一個utils對象,內含一個校驗手機號函數,一個格式化返回數據函數
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 }; } }</pre>