18位身份证校验码验证算法

function checkCode(card){
        if (/^\d{17}[\dxX]$/.test(card))
        {
            var a = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
            var valide = [1,0,'X',9,8,7,6,5,4,3,2];
            var s = 0;
            for (var i = 0; i < card.length - 1; i++)
            {
                s += card.charAt(i) * a[i];
            }
            var mod = s % 11;
            if (valide[mod] != card.charAt(17).toUpperCase())
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        return false;
    }

 

posted on 2017-05-26 18:42  darkness_1  阅读(224)  评论(0编辑  收藏  举报

导航