Weryfikacja numeru IBAN rachunku
function isValidIBANNumber(input) {
var CODE_LENGTHS = {
PL: 28
};
var iban = String(input).toUpperCase().replace(/[^A-Z0-9]/g, ''),
code = iban.match(/^([A-Z]{2})(\d{2})([A-Z\d]+)$/),
digits;
if (!code || iban.length !== CODE_LENGTHS[code[1]] ) {
return false;
}
digits = (code[3] + code[1] + code[2]).replace(/[A-Z]/g, function (letter) {
return letter.charCodeAt(0) - 55;
});
return mod97(digits);
}
function mod97(string) {
var checksum = string.slice(0, 2), fragment;
for (var offset = 2; offset < string.length; offset += 7) {
fragment = String(checksum) + string.substring(offset, offset + 7);
checksum = parseInt(fragment, 10) % 97;
}
return checksum;
}