diff --git a/ChangeLog b/ChangeLog index 65b4efe..91808e5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2026-09-26 Sasha Mitchell + * Czech and Slovak account numbers must be divisible by 11 + 2026-04-10 Saša Jovanić * Version 4.5.4 diff --git a/src/ibantools.ts b/src/ibantools.ts index f565bdd..760012b 100755 --- a/src/ibantools.ts +++ b/src/ibantools.ts @@ -760,24 +760,20 @@ const checkCroatianBBAN = (bban: string): boolean => { const checkCzechAndSlovakBBAN = (bban: string): boolean => { const weightsPrefix = [10, 5, 8, 4, 2, 1]; const weightsSuffix = [6, 3, 7, 9, 10, 5, 8, 4, 2, 1]; - const controlPrefix = parseInt(bban.charAt(9), 10); - const controlSuffix = parseInt(bban.charAt(19), 10); - const prefix = bban.substring(4, 9); - const suffix = bban.substring(10, 19); + const prefix = bban.substring(4, 10); + const suffix = bban.substring(10, 20); let sum = 0; for (let index = 0; index < prefix.length; index++) { sum += parseInt(prefix.charAt(index), 10) * weightsPrefix[index]; } - let remainder = sum % 11; - if (controlPrefix !== (remainder === 0 ? 0 : remainder === 1 ? 1 : 11 - remainder)) { + if (sum % 11 !== 0) { return false; } sum = 0; for (let index = 0; index < suffix.length; index++) { sum += parseInt(suffix.charAt(index), 10) * weightsSuffix[index]; } - remainder = sum % 11; - return controlSuffix === (remainder === 0 ? 0 : remainder === 1 ? 1 : 11 - remainder); + return sum % 11 === 0; }; /** diff --git a/test/ibantools_test.js b/test/ibantools_test.js index 037a995..a2df797 100644 --- a/test/ibantools_test.js +++ b/test/ibantools_test.js @@ -243,6 +243,9 @@ describe('IBANTools', function() { it('with invalid CZ IBAN should return false', function() { return expect(iban.isValidIBAN('CZ6508000000182000145399')).to.be.false; }); + it('with a Czech IBAN whose prefix is not divisible by 11 should return false', function() { + return expect(iban.isValidIBAN('CZ8008000000612000145399')).to.be.false; + }); it('with valid EE IBAN should return true', function() { return expect(iban.isValidIBAN('EE443300338400100007')).to.be.true; });