Skip to content

Commit

Permalink
check country code too
Browse files Browse the repository at this point in the history
  • Loading branch information
bmacnaughton committed Mar 22, 2021
1 parent 2c41f65 commit 0db8241
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/lib/isBIC.js
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 3 additions & 2 deletions src/lib/isISO31661Alpha2.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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;

0 comments on commit 0db8241

Please sign in to comment.