From 73d38ff42e0e8023578ea6f95f891fff8ce48a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sas=CC=8Ca=20Jovanic=CC=81?= Date: Thu, 9 Mar 2017 20:55:53 +0100 Subject: [PATCH] Fix BIC validation and BIC extraction --- dist/ibantools.js | 8 ++++---- src/IBANTools.ts | 8 ++++---- test/IBANToolsTest.ts | 11 +++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/dist/ibantools.js b/dist/ibantools.js index 544f46b..c494f94 100644 --- a/dist/ibantools.js +++ b/dist/ibantools.js @@ -5,11 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ define(["require", "exports"], function (require, exports) { /** - * @file Validation of IBAN numbers and generation of IBAN's plus some other helpful stuff + * @file Validation, extraction and creation of IBAN, BBAN, BIC/SWIFT numbers plus some other helpful stuff * @author Saša Jovanić * @module ibantools * @see module:ibantools - * @version 1.2.0 + * @version 1.3.0 * @license MPL-2.0 */ "use strict"; @@ -235,7 +235,7 @@ define(["require", "exports"], function (require, exports) { * @return {boolean} valid */ function isValidBIC(bic) { - var reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}[XXX0-9]{0,3}$', ''); + var reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}[A-Z0-9]{0,3}$', ''); return reg.test(bic); } exports.isValidBIC = isValidBIC; @@ -255,7 +255,7 @@ define(["require", "exports"], function (require, exports) { result.countryCode = bic.slice(4, 6); result.locationCode = bic.slice(6, 8); result.testBIC = (result.locationCode[1] == '0' ? true : false); - result.branchCode = (bic.length > 8 ? bic.slice(8) : null); + result.branchCode = (bic.length > 8 ? bic.slice(8) : '619'); result.valid = true; } else { diff --git a/src/IBANTools.ts b/src/IBANTools.ts index 73c2632..874f53b 100644 --- a/src/IBANTools.ts +++ b/src/IBANTools.ts @@ -5,11 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * @file Validation of IBAN numbers and generation of IBAN's plus some other helpful stuff + * @file Validation, extraction and creation of IBAN, BBAN, BIC/SWIFT numbers plus some other helpful stuff * @author Saša Jovanić * @module ibantools * @see module:ibantools - * @version 1.2.0 + * @version 1.3.0 * @license MPL-2.0 */ "use strict"; @@ -269,7 +269,7 @@ export function getCountrySpecifications(): CountryMap { * @return {boolean} valid */ export function isValidBIC(bic: string): boolean { - let reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}[XXX0-9]{0,3}$', ''); + let reg = new RegExp('^[a-zA-Z]{6}[a-zA-Z0-9]{2}[A-Z0-9]{0,3}$', ''); return reg.test(bic); } @@ -301,7 +301,7 @@ export function extractBIC(bic: string): ExtractBICResult { result.countryCode = bic.slice(4,6); result.locationCode = bic.slice(6,8); result.testBIC = (result.locationCode[1] == '0' ? true : false); - result.branchCode = (bic.length > 8 ? bic.slice(8) : null); + result.branchCode = (bic.length > 8 ? bic.slice(8) : '619'); result.valid = true; } else { result.valid = false; diff --git a/test/IBANToolsTest.ts b/test/IBANToolsTest.ts index 4806fe3..b47ac78 100644 --- a/test/IBANToolsTest.ts +++ b/test/IBANToolsTest.ts @@ -80,11 +80,14 @@ describe('IBANTools', () => { it('with valid BIC ABNANL2AXXX should return true', function () { expect(iban.isValidBIC('ABNANL2AXXX')).to.be.true; }); + it('with valid BIC NOLADE21KI should return true', function () { + expect(iban.isValidBIC('NOLADE21KIE')).to.be.true; + }); it('with invalid BIC ABN4NL2A should return false', function () { expect(iban.isValidBIC('ABN4NL2A')).to.be.false; }); - it('with invalid BIC ABNANL2A01F should return false', function () { - expect(iban.isValidBIC('ABNANL2A01F')).to.be.false; + it('with invalid BIC ABNANL2A01F should return true', function () { + expect(iban.isValidBIC('ABNANL2A01F')).to.be.true; }); }); @@ -105,8 +108,8 @@ describe('IBANTools', () => { it('testBIC should be false', () => { expect(ext.testBIC).to.be.false; }); - it('branchCode should be null', () => { - expect(ext.branchCode).to.be.null; + it('branchCode should be 619 (primary office)', () => { + expect(ext.branchCode).to.equal('619'); }); });