diff --git a/src/lib/isBIC.js b/src/lib/isBIC.js index bbfdd2035..240bfe18b 100644 --- a/src/lib/isBIC.js +++ b/src/lib/isBIC.js @@ -1,9 +1,17 @@ import assertString from './util/assertString'; +import { CountryCodes } from './isISO31661Alpha2'; // https://en.wikipedia.org/wiki/ISO_9362 const isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/; export default function isBIC(str) { assertString(str); + + // toUpperCase() should be removed when a new major version goes out that changes + // the regex to [A-Z] (per the spec). + if (CountryCodes.indexOf(str.slice(4, 6).toUpperCase()) < 0) { + return false; + } + return isBICReg.test(str); } diff --git a/src/lib/isISO31661Alpha2.js b/src/lib/isISO31661Alpha2.js index ee1c33a40..e91ae8717 100644 --- a/src/lib/isISO31661Alpha2.js +++ b/src/lib/isISO31661Alpha2.js @@ -1,5 +1,4 @@ import assertString from './util/assertString'; -import includes from './util/includes'; // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 const validISO31661Alpha2CountriesCodes = [ @@ -32,5 +31,7 @@ const validISO31661Alpha2CountriesCodes = [ export default function isISO31661Alpha2(str) { assertString(str); - return includes(validISO31661Alpha2CountriesCodes, str.toUpperCase()); + return validISO31661Alpha2CountriesCodes.indexOf(str.toUpperCase()) >= 0; } + +export const CountryCodes = validISO31661Alpha2CountriesCodes;