Skip to content

Commit

Permalink
Fix BIC validation and BIC extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplify committed Mar 9, 2017
1 parent eb4b46f commit 73d38ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions dist/ibantools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/IBANTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions test/IBANToolsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});

Expand All @@ -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');
});
});

Expand Down

0 comments on commit 73d38ff

Please sign in to comment.