Skip to content

Commit

Permalink
feat(isBIC): add isBIC validation (#1071)
Browse files Browse the repository at this point in the history
* feature(isBIC): add isBIC validation
- validate valid BIC
- refers part of #951

* chore: add on BIC definition
  • Loading branch information
ezkemboi authored and profnandaa committed Aug 17, 2019
1 parent c265581 commit 23fcd9c
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Validator | Description
**isBase32(str)** | check if a string is base32 encoded.
**isBase64(str)** | check if a string is base64 encoded.
**isBefore(str [, date])** | check if the string is a date that's before the specified date.
**isBIC(str)** | check if a string is a BIC (Bank Idenfication Code) or SWIFT code.
**isBoolean(str)** | check if a string is a boolean.
**isByteLength(str [, options])** | check if the string's length (in UTF-8 bytes) falls in a range.<br/><br/>`options` is an object which defaults to `{min:0, max: undefined}`.
**isCreditCard(str)** | check if the string is a credit card.
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ var _isHexColor = _interopRequireDefault(require("./lib/isHexColor"));

var _isISRC = _interopRequireDefault(require("./lib/isISRC"));

var _isBIC = _interopRequireDefault(require("./lib/isBIC"));

var _isMD = _interopRequireDefault(require("./lib/isMD5"));

var _isHash = _interopRequireDefault(require("./lib/isHash"));
Expand Down Expand Up @@ -172,6 +174,7 @@ var validator = {
isIPRange: _isIPRange.default,
isFQDN: _isFQDN.default,
isBoolean: _isBoolean.default,
isBIC: _isBIC.default,
isAlpha: _isAlpha.default,
isAlphaLocales: _isAlpha.locales,
isAlphanumeric: _isAlphanumeric.default,
Expand Down
20 changes: 20 additions & 0 deletions lib/isBIC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isBIC;

var _assertString = _interopRequireDefault(require("./util/assertString"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var isBICReg = /^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;

function isBIC(str) {
(0, _assertString.default)(str);
return isBICReg.test(str);
}

module.exports = exports.default;
module.exports.default = exports.default;
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import isHexColor from './lib/isHexColor';

import isISRC from './lib/isISRC';

import isBIC from './lib/isBIC';

import isMD5 from './lib/isMD5';
import isHash from './lib/isHash';
import isJWT from './lib/isJWT';
Expand Down Expand Up @@ -113,6 +115,7 @@ const validator = {
isIPRange,
isFQDN,
isBoolean,
isBIC,
isAlpha,
isAlphaLocales,
isAlphanumeric,
Expand Down
8 changes: 8 additions & 0 deletions src/lib/isBIC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import assertString from './util/assertString';

const isBICReg = /^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;

export default function isBIC(str) {
assertString(str);
return isBICReg.test(str);
}
20 changes: 20 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3002,6 +3002,26 @@ describe('Validators', () => {
});
});

it('should validate BIC codes', () => {
test({
validator: 'isBIC',
valid: [
'SBICKEN1345',
'SBICKEN1',
'SBICKENY',
'SBICKEN1YYP',
],
invalid: [
'SBIC23NXXX',
'S23CKENXXXX',
'SBICKENXX',
'SBICKENXX9',
'SBICKEN13458',
'SBICKEN',
],
});
});

it('should validate that integer strings are divisible by a number', () => {
test({
validator: 'isDivisibleBy',
Expand Down
7 changes: 7 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,12 @@ function isISRC(str) {
return isrc.test(str);
}

var isBICReg = /^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;
function isBIC(str) {
assertString(str);
return isBICReg.test(str);
}

var md5 = /^[a-f0-9]{32}$/;
function isMD5(str) {
assertString(str);
Expand Down Expand Up @@ -2037,6 +2043,7 @@ var validator = {
isIPRange: isIPRange,
isFQDN: isFQDN,
isBoolean: isBoolean,
isBIC: isBIC,
isAlpha: isAlpha,
isAlphaLocales: locales,
isAlphanumeric: isAlphanumeric,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 23fcd9c

Please sign in to comment.