三大运营商电话号码监测

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="http://code.jquery.com/jquery-latest.js" charset="utf-8"></script>
</head>
<body>
    <script>
        var isChinaMobile = /^1(3[0-9]|4[57]|5[0-35-9]|7[0678]|8[0-9])\d{8}$/; //移动134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
        var isChinaUnion = /^1(3[4-9]|4[7]|5[0-27-9]|7[108]|8[2-478])\d{8}$/; //联通130,131,132,145,152,155,156,170,171,176,185,186
        var isChinaTelcom = /^1(3[0-2]|4[5]|5[256]|7[016]|8[56])\d{8}$/; //电信133,134,153,170,177,180,181,189
        var isOtherTelphone  = /^1(3[34]|53|7[07]|8[019])\d{8}$/;//其他运营商
        var utils = {
            checkMobile: function(telphone){
                telphone = $.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
                };
            }
        };
        console.log(utils.checkMobile('18201400827'));
    </script>
</body>
</html>

 

posted @ 2016-09-13 15:49  凉城丶旧梦  阅读(667)  评论(0编辑  收藏  举报