Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(isBIC): add isBIC validation #1071

Merged
merged 3 commits into from Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
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.
**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
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
@@ -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
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
@@ -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
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
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.