Skip to content

Commit 6fbe5d8

Browse files
committed
feature(isBIC): add isBIC validation
- validate valid BIC - refers part of #951
1 parent 54bf8c4 commit 6fbe5d8

File tree

8 files changed

+63
-1
lines changed

8 files changed

+63
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Validator | Description
8383
**isBase32(str)** | check if a string is base32 encoded.
8484
**isBase64(str)** | check if a string is base64 encoded.
8585
**isBefore(str [, date])** | check if the string is a date that's before the specified date.
86+
**isBIC(str)** | check if a string is a BIC.
8687
**isBoolean(str)** | check if a string is a boolean.
8788
**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}`.
8889
**isCreditCard(str)** | check if the string is a credit card.

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ var _isHexColor = _interopRequireDefault(require("./lib/isHexColor"));
7171

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

74+
var _isBIC = _interopRequireDefault(require("./lib/isBIC"));
75+
7476
var _isMD = _interopRequireDefault(require("./lib/isMD5"));
7577

7678
var _isHash = _interopRequireDefault(require("./lib/isHash"));
@@ -172,6 +174,7 @@ var validator = {
172174
isIPRange: _isIPRange.default,
173175
isFQDN: _isFQDN.default,
174176
isBoolean: _isBoolean.default,
177+
isBIC: _isBIC.default,
175178
isAlpha: _isAlpha.default,
176179
isAlphaLocales: _isAlpha.locales,
177180
isAlphanumeric: _isAlphanumeric.default,

lib/isBIC.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.default = isBIC;
7+
8+
var _assertString = _interopRequireDefault(require("./util/assertString"));
9+
10+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11+
12+
var isbic = /^[A-Za-z]{4}[A-Za-z]{2}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
13+
14+
function isBIC(str) {
15+
(0, _assertString.default)(str);
16+
return isbic.test(str);
17+
}
18+
19+
module.exports = exports.default;
20+
module.exports.default = exports.default;

src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import isHexColor from './lib/isHexColor';
3939

4040
import isISRC from './lib/isISRC';
4141

42+
import isBIC from './lib/isBIC';
43+
4244
import isMD5 from './lib/isMD5';
4345
import isHash from './lib/isHash';
4446
import isJWT from './lib/isJWT';
@@ -113,6 +115,7 @@ const validator = {
113115
isIPRange,
114116
isFQDN,
115117
isBoolean,
118+
isBIC,
116119
isAlpha,
117120
isAlphaLocales,
118121
isAlphanumeric,

src/lib/isBIC.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import assertString from './util/assertString';
2+
3+
const isbic = /^[A-Za-z]{4}[A-Za-z]{2}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
4+
5+
export default function isBIC(str) {
6+
assertString(str);
7+
return isbic.test(str);
8+
}

test/validators.js

+20
Original file line numberDiff line numberDiff line change
@@ -2998,6 +2998,26 @@ describe('Validators', () => {
29982998
});
29992999
});
30003000

3001+
it('should validate BIC codes', () => {
3002+
test({
3003+
validator: 'isBIC',
3004+
valid: [
3005+
'SBICKEN1345',
3006+
'SBICKEN1',
3007+
'SBICKENY',
3008+
'SBICKEN1YYP',
3009+
],
3010+
invalid: [
3011+
'SBIC23NXXX',
3012+
'S23CKENXXXX',
3013+
'SBICKENXX',
3014+
'SBICKENXX9',
3015+
'SBICKEN13458',
3016+
'SBICKEN',
3017+
],
3018+
});
3019+
});
3020+
30013021
it('should validate that integer strings are divisible by a number', () => {
30023022
test({
30033023
validator: 'isDivisibleBy',

validator.js

+7
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,12 @@ function isISRC(str) {
940940
return isrc.test(str);
941941
}
942942

943+
var isbic = /^[A-Za-z]{4}[A-Za-z]{2}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
944+
function isBIC(str) {
945+
assertString(str);
946+
return isbic.test(str);
947+
}
948+
943949
var md5 = /^[a-f0-9]{32}$/;
944950
function isMD5(str) {
945951
assertString(str);
@@ -2035,6 +2041,7 @@ var validator = {
20352041
isIPRange: isIPRange,
20362042
isFQDN: isFQDN,
20372043
isBoolean: isBoolean,
2044+
isBIC: isBIC,
20382045
isAlpha: isAlpha,
20392046
isAlphaLocales: locales,
20402047
isAlphanumeric: isAlphanumeric,

validator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)