Created
March 5, 2019 07:36
-
-
Save cuchac/498a7d7fb20fbdfcbfbb1590da896c44 to your computer and use it in GitHub Desktop.
Czech bank account number validity check / Kontrola validnosti českého čísla účtu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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