码迷,mamicode.com
首页 > 编程语言 > 详细

身份证号码正则匹配-javascript

时间:2014-11-15 11:13:17      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   java   for   div   on   log   cti   

   function a(a, b) {
   return a.test(b)
 }
 function b(a) {
   return a = jQuery.trim(a), 0 == a.length
 }
 function c(a) {
   return !b(a)
 }   


    function t(c) {
        if (b(c))
            return !1;
        c = c.toUpperCase();
        var d = {
            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 : "国外"
        }, e = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
        if (a(e, c) === !1)
            return !1;
        var f = c.substr(0, 2);
        if (void 0 == d[f])
            return !1;
        var g = c.length;
        if (15 == g) {
            var h = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/, i = c.match(h), j = s("19"
                    + i[2]), k = s(i[3]), l = s(i[4]), m = new Date("19" + j
                    + "/" + k + "/" + l);
            m.setFullYear(j), m.setMonth(k - 1), m.setDate(l);
            var n = new Date, o = n.getFullYear();
            if (m.getFullYear() != j || m.getMonth() + 1 != k
                    || m.getDate() != l)
                return !1;
            var p = o - j;
            if (!(p >= 3 && 100 >= p))
                return !1
        }
        if (18 == g) {
            var q = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/, i = c
                    .match(q), j = s(i[2]), k = s(i[3]), l = s(i[4]), m = new Date(j
                    + "/" + k + "/" + l);
            m.setFullYear(j), m.setMonth(k - 1), m.setDate(l);
            var n = new Date, o = n.getFullYear();
            if (m.getFullYear() != j || m.getMonth() + 1 != k
                    || m.getDate() != l)
                return !1;
            var p = o - j;
            if (!(p >= 3 && 100 >= p))
                return !1
        }
        if (15 == c.length) {
            var r, t = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8,
                    4, 2), u = new Array("1", "0", "X", "9", "8", "7", "6",
                    "5", "4", "3", "2"), v = 0;
            for (c = c.substr(0, 6) + "19" + c.substr(6, c.length - 6), r = 0; 17 > r; r++)
                v += c.substr(r, 1) * t[r];
            c += u[v % 11]
        }
        if (18 == c.length) {
            var r, w, t = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5,
                    8, 4, 2), u = new Array("1", "0", "X", "9", "8", "7", "6",
                    "5", "4", "3", "2"), v = 0;
            for (r = 0; 17 > r; r++)
                v += parseInt(c.substr(r, 1)) * t[r];
            if (w = u[v % 11], w != c.substr(17, 1))
                return !1
        }
        return !0
    }

  

身份证号码正则匹配-javascript

标签:blog   io   ar   java   for   div   on   log   cti   

原文地址:http://www.cnblogs.com/q446223455/p/4098977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!