本文介绍了IBAN验证检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要使用 javascript 进行 IBAN验证检查

我需要遵循的规则是

验证IBAN
通过将IBAN转换为整数并执行基本的mod-97操作(如ISO 7064中所述)就可以了。如果IBAN有效,则余额等于
1.

Validating the IBANAn IBAN is validated by converting it into an integer and performing a basic mod-97 operation (as described in ISO 7064) on it. If the IBAN is valid, the remainder equals 1.

1 。检查总IBAN长度是否正确国家。如果没有,则IBAN无效

1.Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid

2 。将四个首字母移动到字符串的末尾

2.Move the four initial characters to the end of the string

3 。用两位数字替换字符串中的每个字母,从而扩展字符串,其中A = 10,B = 11,...,Z = 35

3.Replace each letter in the string with two digits, thereby expanding the string, where A = 10, B = 11, ..., Z = 35

4 。将字符串拼凑为十进制整数,并计算除以97的剩余部分

4.Interpret the string as a decimal integer and compute the remainder of that number on division by 97

我正在为白俄罗斯IBAN做这个,所以它必须遵循以下格式

I am doing this for a Belarusian IBAN so it has to follow the following format

2C 31N -

2C 31N -

RU1230000000000000000000000000000

RU1230000000000000000000000000000

如何修改以下内容以符合上述规则;

How do i modify the following to meet the above rules;

function validateIBAN(iban) {
    var newIban = iban.toUpperCase(),
        modulo = function (divident, divisor) {
            var cDivident = '';
            var cRest = '';

            for (var i in divident ) {
                var cChar = divident[i];
                var cOperator = cRest + '' + cDivident + '' + cChar;

                if ( cOperator < parseInt(divisor) ) {
                        cDivident += '' + cChar;
                } else {
                        cRest = cOperator % divisor;
                        if ( cRest == 0 ) {
                            cRest = '';
                        }
                        cDivident = '';
                }

            }
            cRest += '' + cDivident;
            if (cRest == '') {
                cRest = 0;
            }
            return cRest;
        };

    if (newIban.search(/^[A-Z]{2}/gi) < 0) {
        return false;
    }

    newIban = newIban.substring(4) + newIban.substring(0, 4);

    newIban = newIban.replace(/[A-Z]/g, function (match) {
        return match.charCodeAt(0) - 55;
    });

    return parseInt(modulo(newIban, 97), 10) === 1;
}


推荐答案

您可以使用此库来验证并格式化IBAN:(免责声明:我写了这个图书馆)

You can use this library to validate and format an IBAN: https://github.com/arhs/iban.js (disclaimer: I wrote the library)

然而,俄罗斯和白俄罗斯都不受支持,因为我在也不在所以我担心您必须自己修改库代码才能添加它。

However, neither Russia nor Belarus are supported, as I can't find any mention of those countries on the IBAN page of wikipedia nor in the official IBAN registry so I'm afraid you'll have to modify the library code yourself to add it.

这篇关于IBAN验证检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 04:08