Skip to content

Commit b9b67cd

Browse files
committed
Add Dutch BBAN validation
Fixes #415
1 parent 49cb9e9 commit b9b67cd

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed

Diff for: ChangeLog

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
2023-10-14 Saša Jovanić <[email protected]>
1+
2023-12-14 Saša Jovanić <[email protected]>
2+
* Version 4.3.7
3+
* Added Dutch (NL) BBAN validation
4+
5+
2023-11-26 Saša Jovanić <[email protected]>
26
* Version 4.3.6
37

48
2023-11-13 Davide Bianco <[email protected]>

Diff for: dist/ibantools.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ define(["require", "exports"], function (require, exports) {
99
* @package Documentation
1010
* @author Saša Jovanić
1111
* @module ibantools
12-
* @version 4.3.6
12+
* @version 4.3.7
1313
* @license MPL-2.0
1414
* @preferred
1515
*/
@@ -777,6 +777,37 @@ define(["require", "exports"], function (require, exports) {
777777
return controlDigitAccount === (remainder_2 === 0 ? 0 : 10 - remainder_2);
778778
}
779779
};
780+
/**
781+
* Dutch (NL) BBAN check
782+
*
783+
* @ignore
784+
*/
785+
var checkDutchBBAN = function (bban) {
786+
if (bban === '') {
787+
return false;
788+
}
789+
var weights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
790+
var toCheckAccount = bban.substring(4, 14);
791+
if (toCheckAccount.startsWith('000')) {
792+
return true;
793+
}
794+
if (toCheckAccount.startsWith('00')) {
795+
return false;
796+
}
797+
var sum = toCheckAccount
798+
.split('')
799+
.map(function (value, index) {
800+
if (value === '0' && index === 0) {
801+
return 0;
802+
}
803+
var number = parseInt(value, 10);
804+
var weight = weights[index];
805+
return number * weight;
806+
})
807+
.reduce(function (a, b) { return a + b; });
808+
console.log(sum);
809+
return sum % 11 === 0;
810+
};
780811
/**
781812
* Set custom BBAN validation function for country.
782813
*
@@ -1430,6 +1461,7 @@ define(["require", "exports"], function (require, exports) {
14301461
NL: {
14311462
chars: 18,
14321463
bban_regexp: '^[A-Z]{4}[0-9]{10}$',
1464+
bban_validation_func: checkDutchBBAN,
14331465
IBANRegistry: true,
14341466
SEPA: true,
14351467
bank_identifier: '0-3',

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ibantools",
3-
"version": "4.3.6",
3+
"version": "4.3.7",
44
"description": "Validation, extraction and creation of IBAN, BBAN, BIC/SWIFT numbers plus some other helpful stuff like ISO 3136-1 alpha 2 country list",
55
"keywords": [
66
"IBAN",

Diff for: src/ibantools.ts

+27-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @package Documentation
1010
* @author Saša Jovanić
1111
* @module ibantools
12-
* @version 4.3.6
12+
* @version 4.3.7
1313
* @license MPL-2.0
1414
* @preferred
1515
*/
@@ -894,6 +894,31 @@ const checkHungarianBBAN = (bban: string): boolean => {
894894
}
895895
};
896896

897+
/**
898+
* Dutch (NL) BBAN check
899+
*
900+
* @ignore
901+
*/
902+
const checkDutchBBAN = (bban: string): boolean => {
903+
if(bban === '') { return false; }
904+
905+
const weights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
906+
const toCheckAccount = bban.substring(4, 14);
907+
if(toCheckAccount.startsWith('000')) { return true; }
908+
if(toCheckAccount.startsWith('00')) { return false; }
909+
const sum: number = toCheckAccount
910+
.split('')
911+
.map((value: string, index: number) => {
912+
if(value === '0' && index === 0) { return 0; }
913+
const number = parseInt(value, 10);
914+
const weight = weights[index];
915+
return number * weight;
916+
})
917+
.reduce((a: number, b: number) => a + b);
918+
console.log(sum);
919+
return sum % 11 === 0;
920+
}
921+
897922
/**
898923
* Set custom BBAN validation function for country.
899924
*
@@ -1548,6 +1573,7 @@ export const countrySpecs: CountryMapInternal = {
15481573
NL: {
15491574
chars: 18,
15501575
bban_regexp: '^[A-Z]{4}[0-9]{10}$',
1576+
bban_validation_func: checkDutchBBAN,
15511577
IBANRegistry: true,
15521578
SEPA: true,
15531579
bank_identifier: '0-3',

Diff for: test/ibantools_test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ describe('IBANTools', function() {
299299
it('with valid RU IBAN should return true', function() {
300300
expect(iban.isValidIBAN('RU0204452560040702810412345678901')).to.be.true;
301301
});
302+
it('with valid old Postbank Dutch IBAN should return true', function() {
303+
expect(iban.isValidIBAN('NL08INGB0000000555')).to.be.true;
304+
});
305+
it('with invalid Dutch IBAN should return false', function() {
306+
expect(iban.isValidIBAN('NL08INGB0012345555')).to.be.false;
307+
});
302308
it('with two dots should return false', function() {
303309
expect(iban.isValidIBAN('..')).to.be.false;
304310
});
@@ -344,6 +350,7 @@ describe('IBANTools', function() {
344350
errorCodes: [
345351
iban.ValidationErrorsIBAN.WrongBBANLength,
346352
iban.ValidationErrorsIBAN.WrongBBANFormat,
353+
iban.ValidationErrorsIBAN.WrongAccountBankBranchChecksum,
347354
iban.ValidationErrorsIBAN.WrongIBANChecksum,
348355
],
349356
});
@@ -383,7 +390,8 @@ describe('IBANTools', function() {
383390
it('with invalid IBAN checksum should return false with correct code', function() {
384391
expect(iban.validateIBAN('NL91ABNA0517164300')).to.deep.equal({
385392
valid: false,
386-
errorCodes: [iban.ValidationErrorsIBAN.WrongIBANChecksum],
393+
errorCodes: [iban.ValidationErrorsIBAN.WrongAccountBankBranchChecksum,
394+
iban.ValidationErrorsIBAN.WrongIBANChecksum],
387395
});
388396
});
389397

@@ -400,6 +408,7 @@ describe('IBANTools', function() {
400408
errorCodes: [
401409
iban.ValidationErrorsIBAN.WrongBBANLength,
402410
iban.ValidationErrorsIBAN.WrongBBANFormat,
411+
iban.ValidationErrorsIBAN.WrongAccountBankBranchChecksum,
403412
iban.ValidationErrorsIBAN.ChecksumNotNumber,
404413
iban.ValidationErrorsIBAN.WrongIBANChecksum,
405414
],

0 commit comments

Comments
 (0)