• 强大的身份证号码验证,绝对成功


    function getIdCardInfo(idcard){
            var sigma = 0;
            var a = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 );
            var w = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
            for(var i = 0; i < 17; i++) {
                var ai = parseInt(idcard.substring(i, i + 1));
                var wi = a[i];
                sigma += ai * wi;
            }
            var number = sigma % 11;
            return idcard.substring(0,17)+w[number];
        }
        function idCard15To18(id){
            var W = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
            var A = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
            var i,j,s=0;
            var newid;
            newid = id;
            newid = newid.substring(0,6)+"19"+newid.substring(6,id.length);
            for(i=0;i<newid.length;i++ ){
                j= parseInt(newid.substring(i,i+1))*W[i];
                s=s+j;
            }
            s = s % 11;
            newid=newid+A[s];
            return newid;
        }

    js验证,value代码身份证号码

    if(value.length==18){
         return getIdCardInfo(value)==value;
    }else if(value.length==15){
         var id18=idCard15To18(value);
         return getIdCardInfo(id18)==value;
    }else{
         return false;
    }
  • 相关阅读:
    有向无环图单源最短路径问题
    linux下程序编译出错解决方法
    Ceres入门笔记
    Java 中的数据结构类 Vector 和 ArrayList
    102. Binary Tree Level Order Traversal
    104. Maximum Depth of Binary Tree
    101. Symmetric Tree
    100. Same Tree
    490. The Maze
    骑士游历问题
  • 原文地址:https://www.cnblogs.com/snowbaby-kang/p/4549364.html
Copyright © 2020-2023  润新知