捷克国民身份证验证

时间:2015-12-02 06:30:38

标签: algorithm validation identity

我正在寻找CZ国家身份证号码验证算法。可以通过特殊算法对9或10位数字进行排序,但不仅仅是数字:)我发现了这个功能:

function checkId(id) {

    var x, sum_nb=0, check;
    var steps = new Array(7,3,1,7,3,1,7,3);
    id = id.toUpperCase(),
    splitted = id.split("");

    if (splitted.length != 9 && splitted.length != 10) {return false;}

    for (x = 0; x < 9; x++)
    {
        if (x == 0 || x == 1 || x == 2) {
            sum_nb += steps[x] * parseInt(id.charCodeAt(x)-55);
        }
        if (x > 3) {
            sum_nb += steps[x-1] * parseInt(id.charAt(x));
        }
    }

    check = sum_nb % 10;

    if (check == id.charAt(3))
        return true;
    else
        return false;
}

但我不确定它是否正确。有谁知道正确的算法?它可以用任何语言编写,没关系。

0 个答案:

没有答案