Skip to content

Commit

Permalink
Added Croatian (HR) extra BBAN validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplify committed Nov 27, 2021
1 parent b535111 commit f9a1083
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2021-11-27 Saša Jovanić <sasa@simplify.ba>
* Added Croatian (HR) BBAN validation

2021-11-25 Saša Jovanić <sasa@simplify.ba>
* Version 4.1.0
* Added Belgian (BE) extra BBAN validation
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ibantools",
"version": "4.1.0",
"version": "4.1.1",
"description": "Validation, extraction and creation of IBAN, BBAN, BIC/SWIFT numbers plus some other helpful stuff like ISO 3136-1 alpha 2 country list",
"keywords": [
"IBAN",
Expand Down
41 changes: 39 additions & 2 deletions src/IBANTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @package Documentation
* @author Saša Jovanić
* @module ibantools
* @version 4.1.0
* @version 4.1.1
* @license MPL-2.0
* @preferred
*/
Expand Down Expand Up @@ -634,6 +634,37 @@ const checkSpainBBAN = (bban: string): boolean => {
return controlAccount === (remainder === 0 ? 0 : remainder === 1 ? 1 : 11 - remainder);
};

/**
* Mod 11/10 check
*
* @ignore
*/
const checkMod1110 = (toCheck: string, control: number): boolean => {
let nr = 10;
for (let index = 0; index < toCheck.length; index++) {
nr += parseInt(toCheck.charAt(index), 10);
if (nr % 10 !== 0) {
nr = nr % 10;
}
nr = nr * 2;
nr = nr % 11;
}
return control === (11 - nr === 10 ? 0 : 11 - nr);
};

/**
* Croatian (HR) BBAN check
*
* @ignore
*/
const checkCroatianBBAN = (bban: string): boolean => {
const controlBankBranch = parseInt(bban.charAt(6), 10);
const controlAccount = parseInt(bban.charAt(16), 10);
const bankBranch = bban.substring(0, 6);
const account = bban.substring(7, 16);
return checkMod1110(bankBranch, controlBankBranch) && checkMod1110(account, controlAccount);
};

/**
* Country specifications
*/
Expand Down Expand Up @@ -878,7 +909,13 @@ export const countrySpecs: CountryMapInternal = {
chars: 28,
bban_regexp: '^[A-Z]{4}[0-9]{20}$',
},
HR: { chars: 21, bban_regexp: '^[0-9]{17}$', IBANRegistry: true, SEPA: true },
HR: {
chars: 21,
bban_regexp: '^[0-9]{17}$',
bban_validation_func: checkCroatianBBAN,
IBANRegistry: true,
SEPA: true,
},
HT: {},
HU: { chars: 28, bban_regexp: '^[0-9]{24}$', IBANRegistry: true, SEPA: true },
ID: {},
Expand Down

0 comments on commit f9a1083

Please sign in to comment.