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/build/ibantools.js
CHANGED
|
@@ -12,13 +12,26 @@
|
|
|
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
|
*/
|
|
19
19
|
'use strict';
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.countrySpecs = exports.setCountryBBANValidation = exports.
|
|
21
|
+
exports.countrySpecs = exports.setCountryBBANValidation = exports.ValidationErrorsBIC = exports.ValidationErrorsIBAN = void 0;
|
|
22
|
+
exports.isValidIBAN = isValidIBAN;
|
|
23
|
+
exports.validateIBAN = validateIBAN;
|
|
24
|
+
exports.isValidBBAN = isValidBBAN;
|
|
25
|
+
exports.isSEPACountry = isSEPACountry;
|
|
26
|
+
exports.isQRIBAN = isQRIBAN;
|
|
27
|
+
exports.composeIBAN = composeIBAN;
|
|
28
|
+
exports.extractIBAN = extractIBAN;
|
|
29
|
+
exports.electronicFormatIBAN = electronicFormatIBAN;
|
|
30
|
+
exports.friendlyFormatIBAN = friendlyFormatIBAN;
|
|
31
|
+
exports.getCountrySpecifications = getCountrySpecifications;
|
|
32
|
+
exports.isValidBIC = isValidBIC;
|
|
33
|
+
exports.validateBIC = validateBIC;
|
|
34
|
+
exports.extractBIC = extractBIC;
|
|
22
35
|
/**
|
|
23
36
|
* Validate IBAN
|
|
24
37
|
* ```
|
|
@@ -38,13 +51,12 @@ exports.countrySpecs = exports.setCountryBBANValidation = exports.extractBIC = e
|
|
|
38
51
|
* ibantools.isValidIBAN('CH4431999123000889012', { allowQRIBAN: false });
|
|
39
52
|
* ```
|
|
40
53
|
*/
|
|
41
|
-
function isValidIBAN(iban, validationOptions) {
|
|
42
|
-
if (validationOptions === void 0) { validationOptions = { allowQRIBAN: true }; }
|
|
54
|
+
function isValidIBAN(iban, validationOptions = { allowQRIBAN: true }) {
|
|
43
55
|
if (iban === undefined || iban === null)
|
|
44
56
|
return false;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
const reg = new RegExp('^[0-9]{2}$', '');
|
|
58
|
+
const countryCode = iban.slice(0, 2);
|
|
59
|
+
const spec = exports.countrySpecs[countryCode];
|
|
48
60
|
if (spec === undefined || spec.bban_regexp === undefined || spec.bban_regexp === null || spec.chars === undefined)
|
|
49
61
|
return false;
|
|
50
62
|
return (spec.chars === iban.length &&
|
|
@@ -53,7 +65,6 @@ function isValidIBAN(iban, validationOptions) {
|
|
|
53
65
|
isValidIBANChecksum(iban) &&
|
|
54
66
|
(validationOptions.allowQRIBAN || !isQRIBAN(iban)));
|
|
55
67
|
}
|
|
56
|
-
exports.isValidIBAN = isValidIBAN;
|
|
57
68
|
/**
|
|
58
69
|
* IBAM validation errors
|
|
59
70
|
*/
|
|
@@ -84,11 +95,10 @@ var ValidationErrorsIBAN;
|
|
|
84
95
|
* ibantools.validateIBAN('CH4431999123000889012', { allowQRIBAN: false });
|
|
85
96
|
* ```
|
|
86
97
|
*/
|
|
87
|
-
function validateIBAN(iban, validationOptions) {
|
|
88
|
-
|
|
89
|
-
var result = { errorCodes: [], valid: true };
|
|
98
|
+
function validateIBAN(iban, validationOptions = { allowQRIBAN: true }) {
|
|
99
|
+
const result = { errorCodes: [], valid: true };
|
|
90
100
|
if (iban !== undefined && iban !== null && iban !== '') {
|
|
91
|
-
|
|
101
|
+
const spec = exports.countrySpecs[iban.slice(0, 2)];
|
|
92
102
|
if (!spec || !(spec.bban_regexp || spec.chars)) {
|
|
93
103
|
result.valid = false;
|
|
94
104
|
result.errorCodes.push(ValidationErrorsIBAN.NoIBANCountry);
|
|
@@ -106,7 +116,7 @@ function validateIBAN(iban, validationOptions) {
|
|
|
106
116
|
result.valid = false;
|
|
107
117
|
result.errorCodes.push(ValidationErrorsIBAN.WrongAccountBankBranchChecksum);
|
|
108
118
|
}
|
|
109
|
-
|
|
119
|
+
const reg = new RegExp('^[0-9]{2}$', '');
|
|
110
120
|
if (!reg.test(iban.slice(2, 4))) {
|
|
111
121
|
result.valid = false;
|
|
112
122
|
result.errorCodes.push(ValidationErrorsIBAN.ChecksumNotNumber);
|
|
@@ -126,7 +136,6 @@ function validateIBAN(iban, validationOptions) {
|
|
|
126
136
|
}
|
|
127
137
|
return result;
|
|
128
138
|
}
|
|
129
|
-
exports.validateIBAN = validateIBAN;
|
|
130
139
|
/**
|
|
131
140
|
* Validate BBAN
|
|
132
141
|
*
|
|
@@ -142,7 +151,7 @@ exports.validateIBAN = validateIBAN;
|
|
|
142
151
|
function isValidBBAN(bban, countryCode) {
|
|
143
152
|
if (bban === undefined || bban === null || countryCode === undefined || countryCode === null)
|
|
144
153
|
return false;
|
|
145
|
-
|
|
154
|
+
const spec = exports.countrySpecs[countryCode];
|
|
146
155
|
if (spec === undefined ||
|
|
147
156
|
spec === null ||
|
|
148
157
|
spec.bban_regexp === undefined ||
|
|
@@ -158,7 +167,6 @@ function isValidBBAN(bban, countryCode) {
|
|
|
158
167
|
}
|
|
159
168
|
return false;
|
|
160
169
|
}
|
|
161
|
-
exports.isValidBBAN = isValidBBAN;
|
|
162
170
|
/**
|
|
163
171
|
* Validate if country code is from a SEPA country
|
|
164
172
|
* ```
|
|
@@ -172,14 +180,13 @@ exports.isValidBBAN = isValidBBAN;
|
|
|
172
180
|
*/
|
|
173
181
|
function isSEPACountry(countryCode) {
|
|
174
182
|
if (countryCode !== undefined && countryCode !== null) {
|
|
175
|
-
|
|
183
|
+
const spec = exports.countrySpecs[countryCode];
|
|
176
184
|
if (spec !== undefined) {
|
|
177
185
|
return spec.SEPA ? spec.SEPA : false;
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
return false;
|
|
181
189
|
}
|
|
182
|
-
exports.isSEPACountry = isSEPACountry;
|
|
183
190
|
/**
|
|
184
191
|
* Check if IBAN is QR-IBAN
|
|
185
192
|
* ```
|
|
@@ -194,14 +201,13 @@ exports.isSEPACountry = isSEPACountry;
|
|
|
194
201
|
function isQRIBAN(iban) {
|
|
195
202
|
if (iban === undefined || iban === null)
|
|
196
203
|
return false;
|
|
197
|
-
|
|
198
|
-
|
|
204
|
+
const countryCode = iban.slice(0, 2);
|
|
205
|
+
const QRIBANCountries = ['LI', 'CH'];
|
|
199
206
|
if (!QRIBANCountries.includes(countryCode))
|
|
200
207
|
return false;
|
|
201
|
-
|
|
208
|
+
const reg = new RegExp('^3[0-1]{1}[0-9]{3}$', '');
|
|
202
209
|
return reg.test(iban.slice(4, 9));
|
|
203
210
|
}
|
|
204
|
-
exports.isQRIBAN = isQRIBAN;
|
|
205
211
|
/**
|
|
206
212
|
* composeIBAN
|
|
207
213
|
*
|
|
@@ -211,11 +217,11 @@ exports.isQRIBAN = isQRIBAN;
|
|
|
211
217
|
* ```
|
|
212
218
|
*/
|
|
213
219
|
function composeIBAN(params) {
|
|
214
|
-
|
|
220
|
+
const formated_bban = electronicFormatIBAN(params.bban) || '';
|
|
215
221
|
if (params.countryCode === null || params.countryCode === undefined) {
|
|
216
222
|
return null;
|
|
217
223
|
}
|
|
218
|
-
|
|
224
|
+
const spec = exports.countrySpecs[params.countryCode];
|
|
219
225
|
if (formated_bban !== '' &&
|
|
220
226
|
spec !== undefined &&
|
|
221
227
|
spec.chars &&
|
|
@@ -224,12 +230,11 @@ function composeIBAN(params) {
|
|
|
224
230
|
spec.bban_regexp &&
|
|
225
231
|
spec.bban_regexp !== null &&
|
|
226
232
|
checkFormatBBAN(formated_bban, spec.bban_regexp)) {
|
|
227
|
-
|
|
233
|
+
const checksom = mod9710Iban(params.countryCode + '00' + formated_bban);
|
|
228
234
|
return params.countryCode + ('0' + (98 - checksom)).slice(-2) + formated_bban;
|
|
229
235
|
}
|
|
230
236
|
return null;
|
|
231
237
|
}
|
|
232
|
-
exports.composeIBAN = composeIBAN;
|
|
233
238
|
/**
|
|
234
239
|
* extractIBAN
|
|
235
240
|
* ```
|
|
@@ -238,30 +243,30 @@ exports.composeIBAN = composeIBAN;
|
|
|
238
243
|
* ```
|
|
239
244
|
*/
|
|
240
245
|
function extractIBAN(iban) {
|
|
241
|
-
|
|
242
|
-
|
|
246
|
+
const result = {};
|
|
247
|
+
const eFormatIBAN = electronicFormatIBAN(iban);
|
|
243
248
|
result.iban = eFormatIBAN || iban;
|
|
244
249
|
if (!!eFormatIBAN && isValidIBAN(eFormatIBAN)) {
|
|
245
250
|
result.bban = eFormatIBAN.slice(4);
|
|
246
251
|
result.countryCode = eFormatIBAN.slice(0, 2);
|
|
247
252
|
result.valid = true;
|
|
248
|
-
|
|
253
|
+
const spec = exports.countrySpecs[result.countryCode];
|
|
249
254
|
if (spec.account_indentifier) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
255
|
+
const ac = spec.account_indentifier.split('-');
|
|
256
|
+
const starting = parseInt(ac[0]);
|
|
257
|
+
const ending = parseInt(ac[1]);
|
|
253
258
|
result.accountNumber = result.iban.slice(starting, ending + 1);
|
|
254
259
|
}
|
|
255
260
|
if (spec.bank_identifier) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
261
|
+
const ac = spec.bank_identifier.split('-');
|
|
262
|
+
const starting = parseInt(ac[0]);
|
|
263
|
+
const ending = parseInt(ac[1]);
|
|
259
264
|
result.bankIdentifier = result.bban.slice(starting, ending + 1);
|
|
260
265
|
}
|
|
261
266
|
if (spec.branch_indentifier) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
267
|
+
const ac = spec.branch_indentifier.split('-');
|
|
268
|
+
const starting = parseInt(ac[0]);
|
|
269
|
+
const ending = parseInt(ac[1]);
|
|
265
270
|
result.branchIdentifier = result.bban.slice(starting, ending + 1);
|
|
266
271
|
}
|
|
267
272
|
}
|
|
@@ -270,14 +275,13 @@ function extractIBAN(iban) {
|
|
|
270
275
|
}
|
|
271
276
|
return result;
|
|
272
277
|
}
|
|
273
|
-
exports.extractIBAN = extractIBAN;
|
|
274
278
|
/**
|
|
275
279
|
* Check BBAN format
|
|
276
280
|
*
|
|
277
281
|
* @ignore
|
|
278
282
|
*/
|
|
279
283
|
function checkFormatBBAN(bban, bformat) {
|
|
280
|
-
|
|
284
|
+
const reg = new RegExp(bformat, '');
|
|
281
285
|
return reg.test(bban);
|
|
282
286
|
}
|
|
283
287
|
/**
|
|
@@ -295,7 +299,6 @@ function electronicFormatIBAN(iban) {
|
|
|
295
299
|
}
|
|
296
300
|
return iban.replace(/[-\ ]/g, '').toUpperCase();
|
|
297
301
|
}
|
|
298
|
-
exports.electronicFormatIBAN = electronicFormatIBAN;
|
|
299
302
|
/**
|
|
300
303
|
* Get IBAN in friendly format (separated after every 4 characters)
|
|
301
304
|
* IBAN validation is not performed.
|
|
@@ -316,23 +319,22 @@ function friendlyFormatIBAN(iban, separator) {
|
|
|
316
319
|
if (separator === undefined || separator === null) {
|
|
317
320
|
separator = ' ';
|
|
318
321
|
}
|
|
319
|
-
|
|
322
|
+
const electronic_iban = electronicFormatIBAN(iban);
|
|
320
323
|
/* istanbul ignore if */
|
|
321
324
|
if (electronic_iban === null) {
|
|
322
325
|
return null;
|
|
323
326
|
}
|
|
324
327
|
return electronic_iban.replace(/(.{4})(?!$)/g, '$1' + separator);
|
|
325
328
|
}
|
|
326
|
-
exports.friendlyFormatIBAN = friendlyFormatIBAN;
|
|
327
329
|
/**
|
|
328
330
|
* Calculate checksum of IBAN and compares it with checksum provided in IBAN Registry
|
|
329
331
|
*
|
|
330
332
|
* @ignore
|
|
331
333
|
*/
|
|
332
334
|
function isValidIBANChecksum(iban) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
335
|
+
const countryCode = iban.slice(0, 2);
|
|
336
|
+
const providedChecksum = parseInt(iban.slice(2, 4), 10);
|
|
337
|
+
const bban = iban.slice(4);
|
|
336
338
|
// Wikipedia[validating_iban] says there are a specif way to check if a IBAN is valid but
|
|
337
339
|
// it. It says 'If the remainder is 1, the check digit test is passed and the
|
|
338
340
|
// IBAN might be valid.'. might, MIGHT!
|
|
@@ -350,8 +352,8 @@ function isValidIBANChecksum(iban) {
|
|
|
350
352
|
//
|
|
351
353
|
// [validating_iban][https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN]
|
|
352
354
|
// [generating-iban-check][https://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits]
|
|
353
|
-
|
|
354
|
-
|
|
355
|
+
const validationString = replaceCharaterWithCode(`${bban}${countryCode}00`);
|
|
356
|
+
const rest = mod9710(validationString);
|
|
355
357
|
return 98 - rest === providedChecksum;
|
|
356
358
|
}
|
|
357
359
|
/**
|
|
@@ -365,8 +367,8 @@ function replaceCharaterWithCode(str) {
|
|
|
365
367
|
// https://jsbench.me/ttkzgsekae/1
|
|
366
368
|
return str
|
|
367
369
|
.split('')
|
|
368
|
-
.map(
|
|
369
|
-
|
|
370
|
+
.map((c) => {
|
|
371
|
+
const code = c.charCodeAt(0);
|
|
370
372
|
return code >= 65 ? (code - 55).toString() : c;
|
|
371
373
|
})
|
|
372
374
|
.join('');
|
|
@@ -402,9 +404,9 @@ function mod9710Iban(iban) {
|
|
|
402
404
|
* ```
|
|
403
405
|
*/
|
|
404
406
|
function getCountrySpecifications() {
|
|
405
|
-
|
|
406
|
-
for (
|
|
407
|
-
|
|
407
|
+
const countyMap = {};
|
|
408
|
+
for (const countyCode in exports.countrySpecs) {
|
|
409
|
+
const county = exports.countrySpecs[countyCode];
|
|
408
410
|
countyMap[countyCode] = {
|
|
409
411
|
chars: county.chars || null,
|
|
410
412
|
bban_regexp: county.bban_regexp || null,
|
|
@@ -414,7 +416,6 @@ function getCountrySpecifications() {
|
|
|
414
416
|
}
|
|
415
417
|
return countyMap;
|
|
416
418
|
}
|
|
417
|
-
exports.getCountrySpecifications = getCountrySpecifications;
|
|
418
419
|
/**
|
|
419
420
|
* Validate BIC/SWIFT
|
|
420
421
|
*
|
|
@@ -436,11 +437,10 @@ function isValidBIC(bic) {
|
|
|
436
437
|
if (!bic) {
|
|
437
438
|
return false;
|
|
438
439
|
}
|
|
439
|
-
|
|
440
|
-
|
|
440
|
+
const reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$', '');
|
|
441
|
+
const spec = exports.countrySpecs[bic.toUpperCase().slice(4, 6)];
|
|
441
442
|
return reg.test(bic) && spec !== undefined;
|
|
442
443
|
}
|
|
443
|
-
exports.isValidBIC = isValidBIC;
|
|
444
444
|
/**
|
|
445
445
|
* BIC validation errors
|
|
446
446
|
*/
|
|
@@ -458,15 +458,15 @@ var ValidationErrorsBIC;
|
|
|
458
458
|
* ```
|
|
459
459
|
*/
|
|
460
460
|
function validateBIC(bic) {
|
|
461
|
-
|
|
461
|
+
const result = { errorCodes: [], valid: true };
|
|
462
462
|
if (bic !== undefined && bic !== null && bic !== '') {
|
|
463
|
-
|
|
463
|
+
const spec = exports.countrySpecs[bic.toUpperCase().slice(4, 6)];
|
|
464
464
|
if (spec === undefined) {
|
|
465
465
|
result.valid = false;
|
|
466
466
|
result.errorCodes.push(ValidationErrorsBIC.NoBICCountry);
|
|
467
467
|
}
|
|
468
468
|
else {
|
|
469
|
-
|
|
469
|
+
const reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$', '');
|
|
470
470
|
if (!reg.test(bic)) {
|
|
471
471
|
result.valid = false;
|
|
472
472
|
result.errorCodes.push(ValidationErrorsBIC.WrongBICFormat);
|
|
@@ -479,7 +479,6 @@ function validateBIC(bic) {
|
|
|
479
479
|
}
|
|
480
480
|
return result;
|
|
481
481
|
}
|
|
482
|
-
exports.validateBIC = validateBIC;
|
|
483
482
|
/**
|
|
484
483
|
* extractBIC
|
|
485
484
|
* ```
|
|
@@ -488,8 +487,8 @@ exports.validateBIC = validateBIC;
|
|
|
488
487
|
* ```
|
|
489
488
|
*/
|
|
490
489
|
function extractBIC(inputBic) {
|
|
491
|
-
|
|
492
|
-
|
|
490
|
+
const result = {};
|
|
491
|
+
const bic = inputBic.toUpperCase();
|
|
493
492
|
if (isValidBIC(bic)) {
|
|
494
493
|
result.bankCode = bic.slice(0, 4);
|
|
495
494
|
result.countryCode = bic.slice(4, 6);
|
|
@@ -503,22 +502,21 @@ function extractBIC(inputBic) {
|
|
|
503
502
|
}
|
|
504
503
|
return result;
|
|
505
504
|
}
|
|
506
|
-
exports.extractBIC = extractBIC;
|
|
507
505
|
/**
|
|
508
506
|
* Used for Norway BBAN check
|
|
509
507
|
*
|
|
510
508
|
* @ignore
|
|
511
509
|
*/
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
for (
|
|
510
|
+
const checkNorwayBBAN = (bban) => {
|
|
511
|
+
const weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
|
|
512
|
+
const bbanWithoutSpacesAndPeriods = bban.replace(/[\s.]+/g, '');
|
|
513
|
+
const controlDigit = parseInt(bbanWithoutSpacesAndPeriods.charAt(10), 10);
|
|
514
|
+
const bbanWithoutControlDigit = bbanWithoutSpacesAndPeriods.substring(0, 10);
|
|
515
|
+
let sum = 0;
|
|
516
|
+
for (let index = 0; index < 10; index++) {
|
|
519
517
|
sum += parseInt(bbanWithoutControlDigit.charAt(index), 10) * weights[index];
|
|
520
518
|
}
|
|
521
|
-
|
|
519
|
+
const remainder = sum % 11;
|
|
522
520
|
return controlDigit === (remainder === 0 ? 0 : 11 - remainder);
|
|
523
521
|
};
|
|
524
522
|
/**
|
|
@@ -526,11 +524,11 @@ var checkNorwayBBAN = function (bban) {
|
|
|
526
524
|
*
|
|
527
525
|
* @ignore
|
|
528
526
|
*/
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
527
|
+
const checkBelgianBBAN = (bban) => {
|
|
528
|
+
const stripped = bban.replace(/[\s.]+/g, '');
|
|
529
|
+
const checkingPart = parseInt(stripped.substring(0, stripped.length - 2), 10);
|
|
530
|
+
const checksum = parseInt(stripped.substring(stripped.length - 2, stripped.length), 10);
|
|
531
|
+
const remainder = checkingPart % 97 === 0 ? 97 : checkingPart % 97;
|
|
534
532
|
return remainder === checksum;
|
|
535
533
|
};
|
|
536
534
|
/**
|
|
@@ -538,15 +536,15 @@ var checkBelgianBBAN = function (bban) {
|
|
|
538
536
|
*
|
|
539
537
|
* @ignore
|
|
540
538
|
*/
|
|
541
|
-
|
|
539
|
+
const mod9710 = (validationString) => {
|
|
542
540
|
while (validationString.length > 2) {
|
|
543
541
|
// > Any computer programming language or software package that is used to compute D
|
|
544
542
|
// > mod 97 directly must have the ability to handle integers of more than 30 digits.
|
|
545
543
|
// > In practice, this can only be done by software that either supports
|
|
546
544
|
// > arbitrary-precision arithmetic or that can handle 219-bit (unsigned) integers
|
|
547
545
|
// https://en.wikipedia.org/wiki/International_Bank_Account_Number#Modulo_operation_on_IBAN
|
|
548
|
-
|
|
549
|
-
|
|
546
|
+
const part = validationString.slice(0, 6);
|
|
547
|
+
const partInt = parseInt(part, 10);
|
|
550
548
|
if (isNaN(partInt)) {
|
|
551
549
|
return NaN;
|
|
552
550
|
}
|
|
@@ -560,9 +558,9 @@ var mod9710 = function (validationString) {
|
|
|
560
558
|
*
|
|
561
559
|
* @ignore
|
|
562
560
|
*/
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
561
|
+
const checkMod9710BBAN = (bban) => {
|
|
562
|
+
const stripped = bban.replace(/[\s.]+/g, '');
|
|
563
|
+
const reminder = mod9710(stripped);
|
|
566
564
|
return reminder === 1;
|
|
567
565
|
};
|
|
568
566
|
/**
|
|
@@ -570,15 +568,15 @@ var checkMod9710BBAN = function (bban) {
|
|
|
570
568
|
*
|
|
571
569
|
* @ignore
|
|
572
570
|
*/
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
for (
|
|
571
|
+
const checkPolandBBAN = (bban) => {
|
|
572
|
+
const weights = [3, 9, 7, 1, 3, 9, 7];
|
|
573
|
+
const controlDigit = parseInt(bban.charAt(7), 10);
|
|
574
|
+
const toCheck = bban.substring(0, 7);
|
|
575
|
+
let sum = 0;
|
|
576
|
+
for (let index = 0; index < 7; index++) {
|
|
579
577
|
sum += parseInt(toCheck.charAt(index), 10) * weights[index];
|
|
580
578
|
}
|
|
581
|
-
|
|
579
|
+
const remainder = sum % 10;
|
|
582
580
|
return controlDigit === (remainder === 0 ? 0 : 10 - remainder);
|
|
583
581
|
};
|
|
584
582
|
/**
|
|
@@ -586,23 +584,23 @@ var checkPolandBBAN = function (bban) {
|
|
|
586
584
|
*
|
|
587
585
|
* @ignore
|
|
588
586
|
*/
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
for (
|
|
587
|
+
const checkSpainBBAN = (bban) => {
|
|
588
|
+
const weightsBankBranch = [4, 8, 5, 10, 9, 7, 3, 6];
|
|
589
|
+
const weightsAccount = [1, 2, 4, 8, 5, 10, 9, 7, 3, 6];
|
|
590
|
+
const controlBankBranch = parseInt(bban.charAt(8), 10);
|
|
591
|
+
const controlAccount = parseInt(bban.charAt(9), 10);
|
|
592
|
+
const bankBranch = bban.substring(0, 8);
|
|
593
|
+
const account = bban.substring(10, 20);
|
|
594
|
+
let sum = 0;
|
|
595
|
+
for (let index = 0; index < 8; index++) {
|
|
598
596
|
sum += parseInt(bankBranch.charAt(index), 10) * weightsBankBranch[index];
|
|
599
597
|
}
|
|
600
|
-
|
|
598
|
+
let remainder = sum % 11;
|
|
601
599
|
if (controlBankBranch !== (remainder === 0 ? 0 : remainder === 1 ? 1 : 11 - remainder)) {
|
|
602
600
|
return false;
|
|
603
601
|
}
|
|
604
602
|
sum = 0;
|
|
605
|
-
for (
|
|
603
|
+
for (let index = 0; index < 10; index++) {
|
|
606
604
|
sum += parseInt(account.charAt(index), 10) * weightsAccount[index];
|
|
607
605
|
}
|
|
608
606
|
remainder = sum % 11;
|
|
@@ -613,9 +611,9 @@ var checkSpainBBAN = function (bban) {
|
|
|
613
611
|
*
|
|
614
612
|
* @ignore
|
|
615
613
|
*/
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
for (
|
|
614
|
+
const checkMod1110 = (toCheck, control) => {
|
|
615
|
+
let nr = 10;
|
|
616
|
+
for (let index = 0; index < toCheck.length; index++) {
|
|
619
617
|
nr += parseInt(toCheck.charAt(index), 10);
|
|
620
618
|
if (nr % 10 !== 0) {
|
|
621
619
|
nr = nr % 10;
|
|
@@ -630,11 +628,11 @@ var checkMod1110 = function (toCheck, control) {
|
|
|
630
628
|
*
|
|
631
629
|
* @ignore
|
|
632
630
|
*/
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
631
|
+
const checkCroatianBBAN = (bban) => {
|
|
632
|
+
const controlBankBranch = parseInt(bban.charAt(6), 10);
|
|
633
|
+
const controlAccount = parseInt(bban.charAt(16), 10);
|
|
634
|
+
const bankBranch = bban.substring(0, 6);
|
|
635
|
+
const account = bban.substring(7, 16);
|
|
638
636
|
return checkMod1110(bankBranch, controlBankBranch) && checkMod1110(account, controlAccount);
|
|
639
637
|
};
|
|
640
638
|
/**
|
|
@@ -642,23 +640,23 @@ var checkCroatianBBAN = function (bban) {
|
|
|
642
640
|
*
|
|
643
641
|
* @ignore
|
|
644
642
|
*/
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
for (
|
|
643
|
+
const checkCzechAndSlovakBBAN = (bban) => {
|
|
644
|
+
const weightsPrefix = [10, 5, 8, 4, 2, 1];
|
|
645
|
+
const weightsSuffix = [6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
|
|
646
|
+
const controlPrefix = parseInt(bban.charAt(9), 10);
|
|
647
|
+
const controlSuffix = parseInt(bban.charAt(19), 10);
|
|
648
|
+
const prefix = bban.substring(4, 9);
|
|
649
|
+
const suffix = bban.substring(10, 19);
|
|
650
|
+
let sum = 0;
|
|
651
|
+
for (let index = 0; index < prefix.length; index++) {
|
|
654
652
|
sum += parseInt(prefix.charAt(index), 10) * weightsPrefix[index];
|
|
655
653
|
}
|
|
656
|
-
|
|
654
|
+
let remainder = sum % 11;
|
|
657
655
|
if (controlPrefix !== (remainder === 0 ? 0 : remainder === 1 ? 1 : 11 - remainder)) {
|
|
658
656
|
return false;
|
|
659
657
|
}
|
|
660
658
|
sum = 0;
|
|
661
|
-
for (
|
|
659
|
+
for (let index = 0; index < suffix.length; index++) {
|
|
662
660
|
sum += parseInt(suffix.charAt(index), 10) * weightsSuffix[index];
|
|
663
661
|
}
|
|
664
662
|
remainder = sum % 11;
|
|
@@ -669,15 +667,15 @@ var checkCzechAndSlovakBBAN = function (bban) {
|
|
|
669
667
|
*
|
|
670
668
|
* @ignore
|
|
671
669
|
*/
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
for (
|
|
670
|
+
const checkEstonianBBAN = (bban) => {
|
|
671
|
+
const weights = [7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7];
|
|
672
|
+
const controlDigit = parseInt(bban.charAt(15), 10);
|
|
673
|
+
const toCheck = bban.substring(2, 15);
|
|
674
|
+
let sum = 0;
|
|
675
|
+
for (let index = 0; index < toCheck.length; index++) {
|
|
678
676
|
sum += parseInt(toCheck.charAt(index), 10) * weights[index];
|
|
679
677
|
}
|
|
680
|
-
|
|
678
|
+
const remainder = sum % 10;
|
|
681
679
|
return controlDigit === (remainder === 0 ? 0 : 10 - remainder);
|
|
682
680
|
};
|
|
683
681
|
/**
|
|
@@ -686,11 +684,11 @@ var checkEstonianBBAN = function (bban) {
|
|
|
686
684
|
*
|
|
687
685
|
* @ignore
|
|
688
686
|
*/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
for (
|
|
693
|
-
|
|
687
|
+
const checkFrenchBBAN = (bban) => {
|
|
688
|
+
const stripped = bban.replace(/[\s.]+/g, '');
|
|
689
|
+
const normalized = Array.from(stripped);
|
|
690
|
+
for (let index = 0; index < stripped.length; index++) {
|
|
691
|
+
const c = normalized[index].charCodeAt(0);
|
|
694
692
|
if (c >= 65) {
|
|
695
693
|
switch (c) {
|
|
696
694
|
case 65:
|
|
@@ -740,7 +738,7 @@ var checkFrenchBBAN = function (bban) {
|
|
|
740
738
|
}
|
|
741
739
|
}
|
|
742
740
|
}
|
|
743
|
-
|
|
741
|
+
const remainder = mod9710(normalized.join(''));
|
|
744
742
|
return remainder === 0;
|
|
745
743
|
};
|
|
746
744
|
/**
|
|
@@ -748,36 +746,36 @@ var checkFrenchBBAN = function (bban) {
|
|
|
748
746
|
*
|
|
749
747
|
* @ignore
|
|
750
748
|
*/
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
for (
|
|
749
|
+
const checkHungarianBBAN = (bban) => {
|
|
750
|
+
const weights = [9, 7, 3, 1, 9, 7, 3, 1, 9, 7, 3, 1, 9, 7, 3];
|
|
751
|
+
const controlDigitBankBranch = parseInt(bban.charAt(7), 10);
|
|
752
|
+
const toCheckBankBranch = bban.substring(0, 7);
|
|
753
|
+
let sum = 0;
|
|
754
|
+
for (let index = 0; index < toCheckBankBranch.length; index++) {
|
|
757
755
|
sum += parseInt(toCheckBankBranch.charAt(index), 10) * weights[index];
|
|
758
756
|
}
|
|
759
|
-
|
|
757
|
+
const remainder = sum % 10;
|
|
760
758
|
if (controlDigitBankBranch !== (remainder === 0 ? 0 : 10 - remainder)) {
|
|
761
759
|
return false;
|
|
762
760
|
}
|
|
763
761
|
sum = 0;
|
|
764
762
|
if (bban.endsWith('00000000')) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
for (
|
|
763
|
+
const toCheckAccount = bban.substring(8, 15);
|
|
764
|
+
const controlDigitAccount = parseInt(bban.charAt(15), 10);
|
|
765
|
+
for (let index = 0; index < toCheckAccount.length; index++) {
|
|
768
766
|
sum += parseInt(toCheckAccount.charAt(index), 10) * weights[index];
|
|
769
767
|
}
|
|
770
|
-
|
|
771
|
-
return controlDigitAccount === (
|
|
768
|
+
const remainder = sum % 10;
|
|
769
|
+
return controlDigitAccount === (remainder === 0 ? 0 : 10 - remainder);
|
|
772
770
|
}
|
|
773
771
|
else {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
for (
|
|
772
|
+
const toCheckAccount = bban.substring(8, 23);
|
|
773
|
+
const controlDigitAccount = parseInt(bban.charAt(23), 10);
|
|
774
|
+
for (let index = 0; index < toCheckAccount.length; index++) {
|
|
777
775
|
sum += parseInt(toCheckAccount.charAt(index), 10) * weights[index];
|
|
778
776
|
}
|
|
779
|
-
|
|
780
|
-
return controlDigitAccount === (
|
|
777
|
+
const remainder = sum % 10;
|
|
778
|
+
return controlDigitAccount === (remainder === 0 ? 0 : 10 - remainder);
|
|
781
779
|
}
|
|
782
780
|
};
|
|
783
781
|
/**
|
|
@@ -786,7 +784,7 @@ var checkHungarianBBAN = function (bban) {
|
|
|
786
784
|
* If `bban_validation_func` already exists for the corresponding country,
|
|
787
785
|
* it will be overwritten.
|
|
788
786
|
*/
|
|
789
|
-
|
|
787
|
+
const setCountryBBANValidation = (country, func) => {
|
|
790
788
|
if (typeof exports.countrySpecs[country] === 'undefined') {
|
|
791
789
|
return false;
|
|
792
790
|
}
|
|
@@ -988,7 +986,7 @@ exports.countrySpecs = {
|
|
|
988
986
|
IBANRegistry: true,
|
|
989
987
|
SEPA: true,
|
|
990
988
|
bank_identifier: '0-7',
|
|
991
|
-
account_indentifier: '
|
|
989
|
+
account_indentifier: '12-22',
|
|
992
990
|
},
|
|
993
991
|
DJ: {
|
|
994
992
|
chars: 27,
|
|
@@ -1045,7 +1043,7 @@ exports.countrySpecs = {
|
|
|
1045
1043
|
SEPA: true,
|
|
1046
1044
|
branch_indentifier: '4-7',
|
|
1047
1045
|
bank_identifier: '0-3',
|
|
1048
|
-
account_indentifier: '
|
|
1046
|
+
account_indentifier: '14-24',
|
|
1049
1047
|
},
|
|
1050
1048
|
ET: {},
|
|
1051
1049
|
FI: {
|
|
@@ -1452,7 +1450,13 @@ exports.countrySpecs = {
|
|
|
1452
1450
|
NR: {},
|
|
1453
1451
|
NU: {},
|
|
1454
1452
|
NZ: {},
|
|
1455
|
-
OM: {
|
|
1453
|
+
OM: {
|
|
1454
|
+
chars: 23,
|
|
1455
|
+
bban_regexp: '^[0-9]{3}[A-Z0-9]{16}$',
|
|
1456
|
+
IBANRegistry: true,
|
|
1457
|
+
SEPA: false,
|
|
1458
|
+
bank_identifier: '0-2',
|
|
1459
|
+
},
|
|
1456
1460
|
PA: {},
|
|
1457
1461
|
PE: {},
|
|
1458
1462
|
PF: {
|