From fb91c7a862f2b8abfd75efdbb86be246cb80a705 Mon Sep 17 00:00:00 2001 From: yashbudhia Date: Sat, 5 Sep 2026 14:46:32 +0530 Subject: [PATCH] Fix account number extraction for IE, PT, ME, MU and SC (#544) extractIBAN() takes the account number from account_indentifier as inclusive, zero-based positions in the IBAN. Five countries from #544 were either missing the field or had a range that did not match the account number position in the SWIFT IBAN registry: IE added 14-21 (4!a bank, 6!n sort code, 8!n account) PT added 12-22 (4!n bank, 4!n branch, 11!n account, 2!n check) ME 4-22 -> 7-19 (3!n bank, 13!n account, 2!n check; was the whole BBAN) MU 0-30 -> 12-23 (4!a2!n bank, 2!n branch, 12!n account, 3!n, 3!a currency; was the whole IBAN) SC 12-28 -> 12-27 (4!a2!n bank, 2!n branch, 16!n account, 3!a currency; included one currency letter) Tests use the registry's example IBAN for each country. Iceland is left as it is because an existing test pins its current behaviour. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_011ZJQzxtgWvkWobxsDcuLoW --- ChangeLog | 3 ++ src/ibantools.ts | 8 +++-- test/ibantools_test.js | 74 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 65b4efe..613a0fa 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2026-09-05 Yash Budhia + * Fixed account number extraction for IE, PT, ME, MU and SC (#544) + 2026-04-10 Saša Jovanić * Version 4.5.4 diff --git a/src/ibantools.ts b/src/ibantools.ts index f565bdd..7ed8be9 100755 --- a/src/ibantools.ts +++ b/src/ibantools.ts @@ -1308,6 +1308,7 @@ export const countrySpecs: CountryMapInternal = { SEPA: true, branch_indentifier: '4-9', bank_identifier: '0-3', + account_indentifier: '14-21', }, IL: { chars: 23, @@ -1460,7 +1461,7 @@ export const countrySpecs: CountryMapInternal = { bban_validation_func: checkMod9710BBAN, IBANRegistry: true, bank_identifier: '0-2', - account_indentifier: '4-22', + account_indentifier: '7-19', }, MF: { chars: 27, @@ -1522,7 +1523,7 @@ export const countrySpecs: CountryMapInternal = { IBANRegistry: true, branch_indentifier: '6-7', bank_identifier: '0-5', - account_indentifier: '0-30', + account_indentifier: '12-23', }, MV: {}, MW: {}, @@ -1624,6 +1625,7 @@ export const countrySpecs: CountryMapInternal = { IBANRegistry: true, SEPA: true, bank_identifier: '0-3', + account_indentifier: '12-22', }, PW: {}, PY: {}, @@ -1677,7 +1679,7 @@ export const countrySpecs: CountryMapInternal = { IBANRegistry: true, branch_indentifier: '6-7', bank_identifier: '0-5', - account_indentifier: '12-28', + account_indentifier: '12-27', }, SD: { chars: 18, diff --git a/test/ibantools_test.js b/test/ibantools_test.js index 037a995..ab93154 100644 --- a/test/ibantools_test.js +++ b/test/ibantools_test.js @@ -875,6 +875,80 @@ describe('IBANTools', function() { }); }); + describe('When calling extractIBAN() with valid IBAN from Ireland', function() { + var ext = iban.extractIBAN('IE29AIBK93115212345678'); + it('valid should be true', function() { + return expect(ext.valid).to.be.true; + }); + it('accountNumber should be 12345678', function() { + return expect(ext.accountNumber).to.equal('12345678'); + }); + it('bankIdentifier should be AIBK', function() { + return expect(ext.bankIdentifier).to.equal('AIBK'); + }); + it('branchIdentifier should be 931152', function() { + return expect(ext.branchIdentifier).to.equal('931152'); + }); + }); + + describe('When calling extractIBAN() with valid IBAN from Portugal', function() { + var ext = iban.extractIBAN('PT50000201231234567890154'); + it('valid should be true', function() { + return expect(ext.valid).to.be.true; + }); + it('accountNumber should be 12345678901', function() { + return expect(ext.accountNumber).to.equal('12345678901'); + }); + it('bankIdentifier should be 0002', function() { + return expect(ext.bankIdentifier).to.equal('0002'); + }); + }); + + describe('When calling extractIBAN() with valid IBAN from Montenegro', function() { + var ext = iban.extractIBAN('ME25505000012345678951'); + it('valid should be true', function() { + return expect(ext.valid).to.be.true; + }); + it('accountNumber should be 0000123456789', function() { + return expect(ext.accountNumber).to.equal('0000123456789'); + }); + it('bankIdentifier should be 505', function() { + return expect(ext.bankIdentifier).to.equal('505'); + }); + }); + + describe('When calling extractIBAN() with valid IBAN from Mauritius', function() { + var ext = iban.extractIBAN('MU17BOMM0101101030300200000MUR'); + it('valid should be true', function() { + return expect(ext.valid).to.be.true; + }); + it('accountNumber should be 101030300200', function() { + return expect(ext.accountNumber).to.equal('101030300200'); + }); + it('bankIdentifier should be BOMM01', function() { + return expect(ext.bankIdentifier).to.equal('BOMM01'); + }); + it('branchIdentifier should be 01', function() { + return expect(ext.branchIdentifier).to.equal('01'); + }); + }); + + describe('When calling extractIBAN() with valid IBAN from Seychelles', function() { + var ext = iban.extractIBAN('SC18SSCB11010000000000001497USD'); + it('valid should be true', function() { + return expect(ext.valid).to.be.true; + }); + it('accountNumber should be 0000000000001497', function() { + return expect(ext.accountNumber).to.equal('0000000000001497'); + }); + it('bankIdentifier should be SSCB11', function() { + return expect(ext.bankIdentifier).to.equal('SSCB11'); + }); + it('branchIdentifier should be 01', function() { + return expect(ext.branchIdentifier).to.equal('01'); + }); + }); + describe('When calling extractIBAN() with valid IBAN from Andora', function() { var ext = iban.extractIBAN('AD1200012030200359100100'); it('valid should be true', function() {