ibantools 4.5.0 → 4.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/build/ibantools.js +158 -154
- package/jsnext/ibantools.js +145 -141
- package/package.json +18 -21
package/jsnext/ibantools.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @package Documentation
|
|
13
13
|
* @author Saša Jovanić
|
|
14
14
|
* @module ibantools
|
|
15
|
-
* @version 4.5.
|
|
15
|
+
* @version 4.5.2
|
|
16
16
|
* @license MIT or MPL-2.0
|
|
17
17
|
* @preferred
|
|
18
18
|
*/
|
|
@@ -36,13 +36,12 @@
|
|
|
36
36
|
* ibantools.isValidIBAN('CH4431999123000889012', { allowQRIBAN: false });
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export function isValidIBAN(iban, validationOptions) {
|
|
40
|
-
if (validationOptions === void 0) { validationOptions = { allowQRIBAN: true }; }
|
|
39
|
+
export function isValidIBAN(iban, validationOptions = { allowQRIBAN: true }) {
|
|
41
40
|
if (iban === undefined || iban === null)
|
|
42
41
|
return false;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const reg = new RegExp('^[0-9]{2}$', '');
|
|
43
|
+
const countryCode = iban.slice(0, 2);
|
|
44
|
+
const spec = countrySpecs[countryCode];
|
|
46
45
|
if (spec === undefined || spec.bban_regexp === undefined || spec.bban_regexp === null || spec.chars === undefined)
|
|
47
46
|
return false;
|
|
48
47
|
return (spec.chars === iban.length &&
|
|
@@ -81,11 +80,10 @@ export var ValidationErrorsIBAN;
|
|
|
81
80
|
* ibantools.validateIBAN('CH4431999123000889012', { allowQRIBAN: false });
|
|
82
81
|
* ```
|
|
83
82
|
*/
|
|
84
|
-
export function validateIBAN(iban, validationOptions) {
|
|
85
|
-
|
|
86
|
-
var result = { errorCodes: [], valid: true };
|
|
83
|
+
export function validateIBAN(iban, validationOptions = { allowQRIBAN: true }) {
|
|
84
|
+
const result = { errorCodes: [], valid: true };
|
|
87
85
|
if (iban !== undefined && iban !== null && iban !== '') {
|
|
88
|
-
|
|
86
|
+
const spec = countrySpecs[iban.slice(0, 2)];
|
|
89
87
|
if (!spec || !(spec.bban_regexp || spec.chars)) {
|
|
90
88
|
result.valid = false;
|
|
91
89
|
result.errorCodes.push(ValidationErrorsIBAN.NoIBANCountry);
|
|
@@ -103,7 +101,7 @@ export function validateIBAN(iban, validationOptions) {
|
|
|
103
101
|
result.valid = false;
|
|
104
102
|
result.errorCodes.push(ValidationErrorsIBAN.WrongAccountBankBranchChecksum);
|
|
105
103
|
}
|
|
106
|
-
|
|
104
|
+
const reg = new RegExp('^[0-9]{2}$', '');
|
|
107
105
|
if (!reg.test(iban.slice(2, 4))) {
|
|
108
106
|
result.valid = false;
|
|
109
107
|
result.errorCodes.push(ValidationErrorsIBAN.ChecksumNotNumber);
|
|
@@ -138,7 +136,7 @@ export function validateIBAN(iban, validationOptions) {
|
|
|
138
136
|
export function isValidBBAN(bban, countryCode) {
|
|
139
137
|
if (bban === undefined || bban === null || countryCode === undefined || countryCode === null)
|
|
140
138
|
return false;
|
|
141
|
-
|
|
139
|
+
const spec = countrySpecs[countryCode];
|
|
142
140
|
if (spec === undefined ||
|
|
143
141
|
spec === null ||
|
|
144
142
|
spec.bban_regexp === undefined ||
|
|
@@ -167,7 +165,7 @@ export function isValidBBAN(bban, countryCode) {
|
|
|
167
165
|
*/
|
|
168
166
|
export function isSEPACountry(countryCode) {
|
|
169
167
|
if (countryCode !== undefined && countryCode !== null) {
|
|
170
|
-
|
|
168
|
+
const spec = countrySpecs[countryCode];
|
|
171
169
|
if (spec !== undefined) {
|
|
172
170
|
return spec.SEPA ? spec.SEPA : false;
|
|
173
171
|
}
|
|
@@ -188,11 +186,11 @@ export function isSEPACountry(countryCode) {
|
|
|
188
186
|
export function isQRIBAN(iban) {
|
|
189
187
|
if (iban === undefined || iban === null)
|
|
190
188
|
return false;
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
const countryCode = iban.slice(0, 2);
|
|
190
|
+
const QRIBANCountries = ['LI', 'CH'];
|
|
193
191
|
if (!QRIBANCountries.includes(countryCode))
|
|
194
192
|
return false;
|
|
195
|
-
|
|
193
|
+
const reg = new RegExp('^3[0-1]{1}[0-9]{3}$', '');
|
|
196
194
|
return reg.test(iban.slice(4, 9));
|
|
197
195
|
}
|
|
198
196
|
/**
|
|
@@ -204,11 +202,11 @@ export function isQRIBAN(iban) {
|
|
|
204
202
|
* ```
|
|
205
203
|
*/
|
|
206
204
|
export function composeIBAN(params) {
|
|
207
|
-
|
|
205
|
+
const formated_bban = electronicFormatIBAN(params.bban) || '';
|
|
208
206
|
if (params.countryCode === null || params.countryCode === undefined) {
|
|
209
207
|
return null;
|
|
210
208
|
}
|
|
211
|
-
|
|
209
|
+
const spec = countrySpecs[params.countryCode];
|
|
212
210
|
if (formated_bban !== '' &&
|
|
213
211
|
spec !== undefined &&
|
|
214
212
|
spec.chars &&
|
|
@@ -217,7 +215,7 @@ export function composeIBAN(params) {
|
|
|
217
215
|
spec.bban_regexp &&
|
|
218
216
|
spec.bban_regexp !== null &&
|
|
219
217
|
checkFormatBBAN(formated_bban, spec.bban_regexp)) {
|
|
220
|
-
|
|
218
|
+
const checksom = mod9710Iban(params.countryCode + '00' + formated_bban);
|
|
221
219
|
return params.countryCode + ('0' + (98 - checksom)).slice(-2) + formated_bban;
|
|
222
220
|
}
|
|
223
221
|
return null;
|
|
@@ -230,30 +228,30 @@ export function composeIBAN(params) {
|
|
|
230
228
|
* ```
|
|
231
229
|
*/
|
|
232
230
|
export function extractIBAN(iban) {
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
const result = {};
|
|
232
|
+
const eFormatIBAN = electronicFormatIBAN(iban);
|
|
235
233
|
result.iban = eFormatIBAN || iban;
|
|
236
234
|
if (!!eFormatIBAN && isValidIBAN(eFormatIBAN)) {
|
|
237
235
|
result.bban = eFormatIBAN.slice(4);
|
|
238
236
|
result.countryCode = eFormatIBAN.slice(0, 2);
|
|
239
237
|
result.valid = true;
|
|
240
|
-
|
|
238
|
+
const spec = countrySpecs[result.countryCode];
|
|
241
239
|
if (spec.account_indentifier) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
const ac = spec.account_indentifier.split('-');
|
|
241
|
+
const starting = parseInt(ac[0]);
|
|
242
|
+
const ending = parseInt(ac[1]);
|
|
245
243
|
result.accountNumber = result.iban.slice(starting, ending + 1);
|
|
246
244
|
}
|
|
247
245
|
if (spec.bank_identifier) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
const ac = spec.bank_identifier.split('-');
|
|
247
|
+
const starting = parseInt(ac[0]);
|
|
248
|
+
const ending = parseInt(ac[1]);
|
|
251
249
|
result.bankIdentifier = result.bban.slice(starting, ending + 1);
|
|
252
250
|
}
|
|
253
251
|
if (spec.branch_indentifier) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
252
|
+
const ac = spec.branch_indentifier.split('-');
|
|
253
|
+
const starting = parseInt(ac[0]);
|
|
254
|
+
const ending = parseInt(ac[1]);
|
|
257
255
|
result.branchIdentifier = result.bban.slice(starting, ending + 1);
|
|
258
256
|
}
|
|
259
257
|
}
|
|
@@ -268,7 +266,7 @@ export function extractIBAN(iban) {
|
|
|
268
266
|
* @ignore
|
|
269
267
|
*/
|
|
270
268
|
function checkFormatBBAN(bban, bformat) {
|
|
271
|
-
|
|
269
|
+
const reg = new RegExp(bformat, '');
|
|
272
270
|
return reg.test(bban);
|
|
273
271
|
}
|
|
274
272
|
/**
|
|
@@ -306,7 +304,7 @@ export function friendlyFormatIBAN(iban, separator) {
|
|
|
306
304
|
if (separator === undefined || separator === null) {
|
|
307
305
|
separator = ' ';
|
|
308
306
|
}
|
|
309
|
-
|
|
307
|
+
const electronic_iban = electronicFormatIBAN(iban);
|
|
310
308
|
/* istanbul ignore if */
|
|
311
309
|
if (electronic_iban === null) {
|
|
312
310
|
return null;
|
|
@@ -319,9 +317,9 @@ export function friendlyFormatIBAN(iban, separator) {
|
|
|
319
317
|
* @ignore
|
|
320
318
|
*/
|
|
321
319
|
function isValidIBANChecksum(iban) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
320
|
+
const countryCode = iban.slice(0, 2);
|
|
321
|
+
const providedChecksum = parseInt(iban.slice(2, 4), 10);
|
|
322
|
+
const bban = iban.slice(4);
|
|
325
323
|
// Wikipedia[validating_iban] says there are a specif way to check if a IBAN is valid but
|
|
326
324
|
// it. It says 'If the remainder is 1, the check digit test is passed and the
|
|
327
325
|
// IBAN might be valid.'. might, MIGHT!
|
|
@@ -339,8 +337,8 @@ function isValidIBANChecksum(iban) {
|
|
|
339
337
|
//
|
|
340
338
|
// [validating_iban][https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN]
|
|
341
339
|
// [generating-iban-check][https://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits]
|
|
342
|
-
|
|
343
|
-
|
|
340
|
+
const validationString = replaceCharaterWithCode(`${bban}${countryCode}00`);
|
|
341
|
+
const rest = mod9710(validationString);
|
|
344
342
|
return 98 - rest === providedChecksum;
|
|
345
343
|
}
|
|
346
344
|
/**
|
|
@@ -354,8 +352,8 @@ function replaceCharaterWithCode(str) {
|
|
|
354
352
|
// https://jsbench.me/ttkzgsekae/1
|
|
355
353
|
return str
|
|
356
354
|
.split('')
|
|
357
|
-
.map(
|
|
358
|
-
|
|
355
|
+
.map((c) => {
|
|
356
|
+
const code = c.charCodeAt(0);
|
|
359
357
|
return code >= 65 ? (code - 55).toString() : c;
|
|
360
358
|
})
|
|
361
359
|
.join('');
|
|
@@ -391,9 +389,9 @@ function mod9710Iban(iban) {
|
|
|
391
389
|
* ```
|
|
392
390
|
*/
|
|
393
391
|
export function getCountrySpecifications() {
|
|
394
|
-
|
|
395
|
-
for (
|
|
396
|
-
|
|
392
|
+
const countyMap = {};
|
|
393
|
+
for (const countyCode in countrySpecs) {
|
|
394
|
+
const county = countrySpecs[countyCode];
|
|
397
395
|
countyMap[countyCode] = {
|
|
398
396
|
chars: county.chars || null,
|
|
399
397
|
bban_regexp: county.bban_regexp || null,
|
|
@@ -424,8 +422,8 @@ export function isValidBIC(bic) {
|
|
|
424
422
|
if (!bic) {
|
|
425
423
|
return false;
|
|
426
424
|
}
|
|
427
|
-
|
|
428
|
-
|
|
425
|
+
const reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$', '');
|
|
426
|
+
const spec = countrySpecs[bic.toUpperCase().slice(4, 6)];
|
|
429
427
|
return reg.test(bic) && spec !== undefined;
|
|
430
428
|
}
|
|
431
429
|
/**
|
|
@@ -445,15 +443,15 @@ export var ValidationErrorsBIC;
|
|
|
445
443
|
* ```
|
|
446
444
|
*/
|
|
447
445
|
export function validateBIC(bic) {
|
|
448
|
-
|
|
446
|
+
const result = { errorCodes: [], valid: true };
|
|
449
447
|
if (bic !== undefined && bic !== null && bic !== '') {
|
|
450
|
-
|
|
448
|
+
const spec = countrySpecs[bic.toUpperCase().slice(4, 6)];
|
|
451
449
|
if (spec === undefined) {
|
|
452
450
|
result.valid = false;
|
|
453
451
|
result.errorCodes.push(ValidationErrorsBIC.NoBICCountry);
|
|
454
452
|
}
|
|
455
453
|
else {
|
|
456
|
-
|
|
454
|
+
const reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$', '');
|
|
457
455
|
if (!reg.test(bic)) {
|
|
458
456
|
result.valid = false;
|
|
459
457
|
result.errorCodes.push(ValidationErrorsBIC.WrongBICFormat);
|
|
@@ -474,8 +472,8 @@ export function validateBIC(bic) {
|
|
|
474
472
|
* ```
|
|
475
473
|
*/
|
|
476
474
|
export function extractBIC(inputBic) {
|
|
477
|
-
|
|
478
|
-
|
|
475
|
+
const result = {};
|
|
476
|
+
const bic = inputBic.toUpperCase();
|
|
479
477
|
if (isValidBIC(bic)) {
|
|
480
478
|
result.bankCode = bic.slice(0, 4);
|
|
481
479
|
result.countryCode = bic.slice(4, 6);
|
|
@@ -494,16 +492,16 @@ export function extractBIC(inputBic) {
|
|
|
494
492
|
*
|
|
495
493
|
* @ignore
|
|
496
494
|
*/
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
for (
|
|
495
|
+
const checkNorwayBBAN = (bban) => {
|
|
496
|
+
const weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
|
|
497
|
+
const bbanWithoutSpacesAndPeriods = bban.replace(/[\s.]+/g, '');
|
|
498
|
+
const controlDigit = parseInt(bbanWithoutSpacesAndPeriods.charAt(10), 10);
|
|
499
|
+
const bbanWithoutControlDigit = bbanWithoutSpacesAndPeriods.substring(0, 10);
|
|
500
|
+
let sum = 0;
|
|
501
|
+
for (let index = 0; index < 10; index++) {
|
|
504
502
|
sum += parseInt(bbanWithoutControlDigit.charAt(index), 10) * weights[index];
|
|
505
503
|
}
|
|
506
|
-
|
|
504
|
+
const remainder = sum % 11;
|
|
507
505
|
return controlDigit === (remainder === 0 ? 0 : 11 - remainder);
|
|
508
506
|
};
|
|
509
507
|
/**
|
|
@@ -511,11 +509,11 @@ var checkNorwayBBAN = function (bban) {
|
|
|
511
509
|
*
|
|
512
510
|
* @ignore
|
|
513
511
|
*/
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
512
|
+
const checkBelgianBBAN = (bban) => {
|
|
513
|
+
const stripped = bban.replace(/[\s.]+/g, '');
|
|
514
|
+
const checkingPart = parseInt(stripped.substring(0, stripped.length - 2), 10);
|
|
515
|
+
const checksum = parseInt(stripped.substring(stripped.length - 2, stripped.length), 10);
|
|
516
|
+
const remainder = checkingPart % 97 === 0 ? 97 : checkingPart % 97;
|
|
519
517
|
return remainder === checksum;
|
|
520
518
|
};
|
|
521
519
|
/**
|
|
@@ -523,15 +521,15 @@ var checkBelgianBBAN = function (bban) {
|
|
|
523
521
|
*
|
|
524
522
|
* @ignore
|
|
525
523
|
*/
|
|
526
|
-
|
|
524
|
+
const mod9710 = (validationString) => {
|
|
527
525
|
while (validationString.length > 2) {
|
|
528
526
|
// > Any computer programming language or software package that is used to compute D
|
|
529
527
|
// > mod 97 directly must have the ability to handle integers of more than 30 digits.
|
|
530
528
|
// > In practice, this can only be done by software that either supports
|
|
531
529
|
// > arbitrary-precision arithmetic or that can handle 219-bit (unsigned) integers
|
|
532
530
|
// https://en.wikipedia.org/wiki/International_Bank_Account_Number#Modulo_operation_on_IBAN
|
|
533
|
-
|
|
534
|
-
|
|
531
|
+
const part = validationString.slice(0, 6);
|
|
532
|
+
const partInt = parseInt(part, 10);
|
|
535
533
|
if (isNaN(partInt)) {
|
|
536
534
|
return NaN;
|
|
537
535
|
}
|
|
@@ -545,9 +543,9 @@ var mod9710 = function (validationString) {
|
|
|
545
543
|
*
|
|
546
544
|
* @ignore
|
|
547
545
|
*/
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
546
|
+
const checkMod9710BBAN = (bban) => {
|
|
547
|
+
const stripped = bban.replace(/[\s.]+/g, '');
|
|
548
|
+
const reminder = mod9710(stripped);
|
|
551
549
|
return reminder === 1;
|
|
552
550
|
};
|
|
553
551
|
/**
|
|
@@ -555,15 +553,15 @@ var checkMod9710BBAN = function (bban) {
|
|
|
555
553
|
*
|
|
556
554
|
* @ignore
|
|
557
555
|
*/
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
for (
|
|
556
|
+
const checkPolandBBAN = (bban) => {
|
|
557
|
+
const weights = [3, 9, 7, 1, 3, 9, 7];
|
|
558
|
+
const controlDigit = parseInt(bban.charAt(7), 10);
|
|
559
|
+
const toCheck = bban.substring(0, 7);
|
|
560
|
+
let sum = 0;
|
|
561
|
+
for (let index = 0; index < 7; index++) {
|
|
564
562
|
sum += parseInt(toCheck.charAt(index), 10) * weights[index];
|
|
565
563
|
}
|
|
566
|
-
|
|
564
|
+
const remainder = sum % 10;
|
|
567
565
|
return controlDigit === (remainder === 0 ? 0 : 10 - remainder);
|
|
568
566
|
};
|
|
569
567
|
/**
|
|
@@ -571,23 +569,23 @@ var checkPolandBBAN = function (bban) {
|
|
|
571
569
|
*
|
|
572
570
|
* @ignore
|
|
573
571
|
*/
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
for (
|
|
572
|
+
const checkSpainBBAN = (bban) => {
|
|
573
|
+
const weightsBankBranch = [4, 8, 5, 10, 9, 7, 3, 6];
|
|
574
|
+
const weightsAccount = [1, 2, 4, 8, 5, 10, 9, 7, 3, 6];
|
|
575
|
+
const controlBankBranch = parseInt(bban.charAt(8), 10);
|
|
576
|
+
const controlAccount = parseInt(bban.charAt(9), 10);
|
|
577
|
+
const bankBranch = bban.substring(0, 8);
|
|
578
|
+
const account = bban.substring(10, 20);
|
|
579
|
+
let sum = 0;
|
|
580
|
+
for (let index = 0; index < 8; index++) {
|
|
583
581
|
sum += parseInt(bankBranch.charAt(index), 10) * weightsBankBranch[index];
|
|
584
582
|
}
|
|
585
|
-
|
|
583
|
+
let remainder = sum % 11;
|
|
586
584
|
if (controlBankBranch !== (remainder === 0 ? 0 : remainder === 1 ? 1 : 11 - remainder)) {
|
|
587
585
|
return false;
|
|
588
586
|
}
|
|
589
587
|
sum = 0;
|
|
590
|
-
for (
|
|
588
|
+
for (let index = 0; index < 10; index++) {
|
|
591
589
|
sum += parseInt(account.charAt(index), 10) * weightsAccount[index];
|
|
592
590
|
}
|
|
593
591
|
remainder = sum % 11;
|
|
@@ -598,9 +596,9 @@ var checkSpainBBAN = function (bban) {
|
|
|
598
596
|
*
|
|
599
597
|
* @ignore
|
|
600
598
|
*/
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
for (
|
|
599
|
+
const checkMod1110 = (toCheck, control) => {
|
|
600
|
+
let nr = 10;
|
|
601
|
+
for (let index = 0; index < toCheck.length; index++) {
|
|
604
602
|
nr += parseInt(toCheck.charAt(index), 10);
|
|
605
603
|
if (nr % 10 !== 0) {
|
|
606
604
|
nr = nr % 10;
|
|
@@ -615,11 +613,11 @@ var checkMod1110 = function (toCheck, control) {
|
|
|
615
613
|
*
|
|
616
614
|
* @ignore
|
|
617
615
|
*/
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
616
|
+
const checkCroatianBBAN = (bban) => {
|
|
617
|
+
const controlBankBranch = parseInt(bban.charAt(6), 10);
|
|
618
|
+
const controlAccount = parseInt(bban.charAt(16), 10);
|
|
619
|
+
const bankBranch = bban.substring(0, 6);
|
|
620
|
+
const account = bban.substring(7, 16);
|
|
623
621
|
return checkMod1110(bankBranch, controlBankBranch) && checkMod1110(account, controlAccount);
|
|
624
622
|
};
|
|
625
623
|
/**
|
|
@@ -627,23 +625,23 @@ var checkCroatianBBAN = function (bban) {
|
|
|
627
625
|
*
|
|
628
626
|
* @ignore
|
|
629
627
|
*/
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
for (
|
|
628
|
+
const checkCzechAndSlovakBBAN = (bban) => {
|
|
629
|
+
const weightsPrefix = [10, 5, 8, 4, 2, 1];
|
|
630
|
+
const weightsSuffix = [6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
|
|
631
|
+
const controlPrefix = parseInt(bban.charAt(9), 10);
|
|
632
|
+
const controlSuffix = parseInt(bban.charAt(19), 10);
|
|
633
|
+
const prefix = bban.substring(4, 9);
|
|
634
|
+
const suffix = bban.substring(10, 19);
|
|
635
|
+
let sum = 0;
|
|
636
|
+
for (let index = 0; index < prefix.length; index++) {
|
|
639
637
|
sum += parseInt(prefix.charAt(index), 10) * weightsPrefix[index];
|
|
640
638
|
}
|
|
641
|
-
|
|
639
|
+
let remainder = sum % 11;
|
|
642
640
|
if (controlPrefix !== (remainder === 0 ? 0 : remainder === 1 ? 1 : 11 - remainder)) {
|
|
643
641
|
return false;
|
|
644
642
|
}
|
|
645
643
|
sum = 0;
|
|
646
|
-
for (
|
|
644
|
+
for (let index = 0; index < suffix.length; index++) {
|
|
647
645
|
sum += parseInt(suffix.charAt(index), 10) * weightsSuffix[index];
|
|
648
646
|
}
|
|
649
647
|
remainder = sum % 11;
|
|
@@ -654,15 +652,15 @@ var checkCzechAndSlovakBBAN = function (bban) {
|
|
|
654
652
|
*
|
|
655
653
|
* @ignore
|
|
656
654
|
*/
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
for (
|
|
655
|
+
const checkEstonianBBAN = (bban) => {
|
|
656
|
+
const weights = [7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7];
|
|
657
|
+
const controlDigit = parseInt(bban.charAt(15), 10);
|
|
658
|
+
const toCheck = bban.substring(2, 15);
|
|
659
|
+
let sum = 0;
|
|
660
|
+
for (let index = 0; index < toCheck.length; index++) {
|
|
663
661
|
sum += parseInt(toCheck.charAt(index), 10) * weights[index];
|
|
664
662
|
}
|
|
665
|
-
|
|
663
|
+
const remainder = sum % 10;
|
|
666
664
|
return controlDigit === (remainder === 0 ? 0 : 10 - remainder);
|
|
667
665
|
};
|
|
668
666
|
/**
|
|
@@ -671,11 +669,11 @@ var checkEstonianBBAN = function (bban) {
|
|
|
671
669
|
*
|
|
672
670
|
* @ignore
|
|
673
671
|
*/
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
for (
|
|
678
|
-
|
|
672
|
+
const checkFrenchBBAN = (bban) => {
|
|
673
|
+
const stripped = bban.replace(/[\s.]+/g, '');
|
|
674
|
+
const normalized = Array.from(stripped);
|
|
675
|
+
for (let index = 0; index < stripped.length; index++) {
|
|
676
|
+
const c = normalized[index].charCodeAt(0);
|
|
679
677
|
if (c >= 65) {
|
|
680
678
|
switch (c) {
|
|
681
679
|
case 65:
|
|
@@ -725,7 +723,7 @@ var checkFrenchBBAN = function (bban) {
|
|
|
725
723
|
}
|
|
726
724
|
}
|
|
727
725
|
}
|
|
728
|
-
|
|
726
|
+
const remainder = mod9710(normalized.join(''));
|
|
729
727
|
return remainder === 0;
|
|
730
728
|
};
|
|
731
729
|
/**
|
|
@@ -733,36 +731,36 @@ var checkFrenchBBAN = function (bban) {
|
|
|
733
731
|
*
|
|
734
732
|
* @ignore
|
|
735
733
|
*/
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
for (
|
|
734
|
+
const checkHungarianBBAN = (bban) => {
|
|
735
|
+
const weights = [9, 7, 3, 1, 9, 7, 3, 1, 9, 7, 3, 1, 9, 7, 3];
|
|
736
|
+
const controlDigitBankBranch = parseInt(bban.charAt(7), 10);
|
|
737
|
+
const toCheckBankBranch = bban.substring(0, 7);
|
|
738
|
+
let sum = 0;
|
|
739
|
+
for (let index = 0; index < toCheckBankBranch.length; index++) {
|
|
742
740
|
sum += parseInt(toCheckBankBranch.charAt(index), 10) * weights[index];
|
|
743
741
|
}
|
|
744
|
-
|
|
742
|
+
const remainder = sum % 10;
|
|
745
743
|
if (controlDigitBankBranch !== (remainder === 0 ? 0 : 10 - remainder)) {
|
|
746
744
|
return false;
|
|
747
745
|
}
|
|
748
746
|
sum = 0;
|
|
749
747
|
if (bban.endsWith('00000000')) {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
for (
|
|
748
|
+
const toCheckAccount = bban.substring(8, 15);
|
|
749
|
+
const controlDigitAccount = parseInt(bban.charAt(15), 10);
|
|
750
|
+
for (let index = 0; index < toCheckAccount.length; index++) {
|
|
753
751
|
sum += parseInt(toCheckAccount.charAt(index), 10) * weights[index];
|
|
754
752
|
}
|
|
755
|
-
|
|
756
|
-
return controlDigitAccount === (
|
|
753
|
+
const remainder = sum % 10;
|
|
754
|
+
return controlDigitAccount === (remainder === 0 ? 0 : 10 - remainder);
|
|
757
755
|
}
|
|
758
756
|
else {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
for (
|
|
757
|
+
const toCheckAccount = bban.substring(8, 23);
|
|
758
|
+
const controlDigitAccount = parseInt(bban.charAt(23), 10);
|
|
759
|
+
for (let index = 0; index < toCheckAccount.length; index++) {
|
|
762
760
|
sum += parseInt(toCheckAccount.charAt(index), 10) * weights[index];
|
|
763
761
|
}
|
|
764
|
-
|
|
765
|
-
return controlDigitAccount === (
|
|
762
|
+
const remainder = sum % 10;
|
|
763
|
+
return controlDigitAccount === (remainder === 0 ? 0 : 10 - remainder);
|
|
766
764
|
}
|
|
767
765
|
};
|
|
768
766
|
/**
|
|
@@ -771,7 +769,7 @@ var checkHungarianBBAN = function (bban) {
|
|
|
771
769
|
* If `bban_validation_func` already exists for the corresponding country,
|
|
772
770
|
* it will be overwritten.
|
|
773
771
|
*/
|
|
774
|
-
export
|
|
772
|
+
export const setCountryBBANValidation = (country, func) => {
|
|
775
773
|
if (typeof countrySpecs[country] === 'undefined') {
|
|
776
774
|
return false;
|
|
777
775
|
}
|
|
@@ -781,7 +779,7 @@ export var setCountryBBANValidation = function (country, func) {
|
|
|
781
779
|
/**
|
|
782
780
|
* Country specifications
|
|
783
781
|
*/
|
|
784
|
-
export
|
|
782
|
+
export const countrySpecs = {
|
|
785
783
|
AD: {
|
|
786
784
|
chars: 24,
|
|
787
785
|
bban_regexp: '^[0-9]{8}[A-Z0-9]{12}$',
|
|
@@ -972,7 +970,7 @@ export var countrySpecs = {
|
|
|
972
970
|
IBANRegistry: true,
|
|
973
971
|
SEPA: true,
|
|
974
972
|
bank_identifier: '0-7',
|
|
975
|
-
account_indentifier: '
|
|
973
|
+
account_indentifier: '12-22',
|
|
976
974
|
},
|
|
977
975
|
DJ: {
|
|
978
976
|
chars: 27,
|
|
@@ -1029,7 +1027,7 @@ export var countrySpecs = {
|
|
|
1029
1027
|
SEPA: true,
|
|
1030
1028
|
branch_indentifier: '4-7',
|
|
1031
1029
|
bank_identifier: '0-3',
|
|
1032
|
-
account_indentifier: '
|
|
1030
|
+
account_indentifier: '14-24',
|
|
1033
1031
|
},
|
|
1034
1032
|
ET: {},
|
|
1035
1033
|
FI: {
|
|
@@ -1436,7 +1434,13 @@ export var countrySpecs = {
|
|
|
1436
1434
|
NR: {},
|
|
1437
1435
|
NU: {},
|
|
1438
1436
|
NZ: {},
|
|
1439
|
-
OM: {
|
|
1437
|
+
OM: {
|
|
1438
|
+
chars: 23,
|
|
1439
|
+
bban_regexp: '^[0-9]{3}[A-Z0-9]{16}$',
|
|
1440
|
+
IBANRegistry: true,
|
|
1441
|
+
SEPA: false,
|
|
1442
|
+
bank_identifier: '0-2',
|
|
1443
|
+
},
|
|
1440
1444
|
PA: {},
|
|
1441
1445
|
PE: {},
|
|
1442
1446
|
PF: {
|