Skip to content

Instantly share code, notes, and snippets.

@cuchac
Created March 5, 2019 07:36
Show Gist options
  • Save cuchac/498a7d7fb20fbdfcbfbb1590da896c44 to your computer and use it in GitHub Desktop.
Save cuchac/498a7d7fb20fbdfcbfbb1590da896c44 to your computer and use it in GitHub Desktop.
Czech bank account number validity check / Kontrola validnosti českého čísla účtu
function checkBankAccountNumber(account) {
var matches = /^(([0-9]{0,6})-)?([0-9]{1,10})\/([0-9]{1,6})$/.exec(account);
if (!matches) {
return false;
}
return checkDigit11(matches[2]) && checkDigit11(matches[3]);
}
function checkDigit11(n, x) {
var l = n.length - 1, i = 0, v = 0;
var weights = [1, 2, 4, 8, 5, 10, 9, 7, 3, 6];
for(i = 0; i <= l; i++) {
console.log(i, n[l-i], weights[i], );
v += parseInt(n[l-i], 10) * weights[i];
}
return v%11 == 0;
};
checkBankAccountNumber('123456-1234567890/1234');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment