Last active
December 6, 2021 10:45
-
-
Save rarous/4e8451c8e4b4319edf399d8fce995afe to your computer and use it in GitHub Desktop.
Validace IČ
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
export function registrationNumberValidator(regNr) { | |
if (!regNr || (typeof regNr !== "string") || regNr.length !== 8) return false; | |
const [n8, n7, n6, n5, n4, n3, n2, x] = regNr.split("").map(Number); | |
return ( | |
x === | |
(11 - | |
((8 * n8 + 7 * n7 + 6 * n6 + 5 * n5 + 4 * n4 + 3 * n3 + 2 * n2) % 11)) % | |
10 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment