国内手机号段校验正则表达式

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

国内手机号段校验正则
附加一个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
        };
    }
}

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...