常用正则表达式

手机号码验证:

!(/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(num))

银行卡验证:

!(/^(\d{16}|\d{19})$/).test(card))

简单的身份证号码验证:

!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))

身份证号码验证并解析相关信息:

$('#J_in_card').blur(function(){  //失去焦点则触发
    var code = $('#J_in_card').val();
    var city = {11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
    var pass = true;
    var addr = '';
    if(!code || !(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(code)) || !city[code.substr(0,2)]){
        warntips('身份证格式错误','#J_in_card');
        pass = false;
    }else{
        //获取户籍地省份
        addr = city[code.substr(0,2)];
        //15位的身份证
        if(code.length == 15){
            //获取生日
            var birth = '19'+code.substr(6,2)+'-'+code.substr(8,2)+'-'+code.substr(10,2);
            var sex = code.substr(12,3);
            if(parseInt(sex) % 2 == 0){
                //相当于鼠标点击选择事件
                $('#J_woman').next().trigger("click");
            }else{
                $('#J_man').next().trigger("click");
            }
        }else{
            var birth = code.substr(6,4)+'-'+code.substr(10,2)+'-'+code.substr(12,2);
            var sex = code.substr(14,3);
            if(parseInt(sex) % 2 == 0){
                $('#J_woman').next().trigger("click");
            }else{
                $('#J_man').next().trigger("click");
            }
        }
        $('#J_birth').val(birth);
        $('#J_id_address').val(addr);
    }
    return pass;
});
posted @ 2016-07-08 15:56  IT~民工  阅读(169)  评论(0编辑  收藏  举报