diff --git a/README.md b/README.md index 53bc33529..9bf2e47b5 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ Validator | Description **isHash(str, algorithm)** | check if the string is a hash of type algorithm.

Algorithm is one of `['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']` **isHexColor(str)** | check if the string is a hexadecimal color. **isHexadecimal(str)** | check if the string is a hexadecimal number. +**isIBAN(str, locale)** | check if the string is a valid IBAN number,

(locale is one of `[ 'AD', 'AT', 'AU', 'BE', 'BG', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'ID', 'IL', 'IN', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SA', 'SE', 'SI', 'TN', 'TW', 'UA', 'US', 'ZA', 'ZM' ]` OR 'any'. If 'any' is used, function will check if any of the locals match with the first twi caracters of the IBAN number (wich corresponds to the ISO 3166-1 alpha-2 country code). Locale list is `validator.isIBANLocales`). **isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'zh-TW', 'he-IL']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIP(str [, version])** | check if the string is an IP (version 4 or 6). **isIPRange(str)** | check if the string is an IP Range(version 4 only). diff --git a/index.js b/index.js index 0af96d5e6..01233eb61 100644 --- a/index.js +++ b/index.js @@ -151,6 +151,10 @@ var _isWhitelisted = _interopRequireDefault(require("./lib/isWhitelisted")); var _normalizeEmail = _interopRequireDefault(require("./lib/normalizeEmail")); +var _toString = _interopRequireDefault(require("./lib/util/toString")); + +var _isIBAN = _interopRequireWildcard(require("./lib/isIBAN")); + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -236,7 +240,9 @@ var validator = { blacklist: _blacklist.default, isWhitelisted: _isWhitelisted.default, normalizeEmail: _normalizeEmail.default, - toString: toString + toString: _toString.default, + isIBAN: _isIBAN.default, + isIBANLocales: _isIBAN.locales }; var _default = validator; exports.default = _default; diff --git a/lib/isIBAN.js b/lib/isIBAN.js new file mode 100644 index 000000000..29bd60593 --- /dev/null +++ b/lib/isIBAN.js @@ -0,0 +1,128 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = isIBAN; +exports.locales = void 0; + +var _assertString = _interopRequireDefault(require("./util/assertString")); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/* eslint-disable max-len */ +var iban = { + AD: /^(AD[0-9]{2})\d{8}[0-9A-Z]{12}$/, + AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/, + AT: /^(AT[0-9]{2})\d{16}$/, + BA: /^(BA[0-9]{2})\d{16}$/, + BE: /^(BE[0-9]{2})\d{12}$/, + BG: /^(BG[0-9]{2})[A-Z]{4}\d{4}[A-Z0-9]{10}$/, + BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/, + BR: /^(BR[0-9]{2})\d{23}[A-Z][A-Z0-9]$/, + CH: /^(CH[0-9]{2})\d{17}$/, + CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/, + CZ: /^(CZ[0-9]{2})\d{20}$/, + DE: /^(DE[0-9]{2})\d{18}$/, + DK: /^(DK[0-9]{2})\d{14}$/, + EE: /^(EE[0-9]{2})\d{16}$/, + ES: /^(ES[0-9]{2})\d{20}$/, + FO: /^(FO[0-9]{2})\d{14}$/, + FI: /^(FI[0-9]{2})\d{14}$/, + FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/, + GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/, + GE: /^(GE[0-9]{2})[A-Z]{2}\d{16}$/, + GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/, + GL: /^(GL[0-9]{2})\d{14}$/, + GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/, + HR: /^(HR[0-9]{2})\d{17}$/, + HU: /^(HU[0-9]{2})\d{24}$/, + IE: /^(IE[0-9]{2})[A-Z]{4}\d{14}$/, + IS: /^(IS[0-9]{2})\d{22}$/, + IT: /^(IT[0-9]{2})[A-Z]\d{10}[A-Z0-9]{12}$/, + JO: /^(JO[0-9]{2})[A-Z]{4}\d{4}[A-Z0-9]{18}$/, + KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/, + KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/, + LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/, + LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/, + LT: /^(LT[0-9]{2})\d{16}$/, + LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/, + LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/, + MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/, + MD: /^(MD[0-9]{2})[A-Z]{2}[A-Z0-9]{18}$/, + ME: /^(ME[0-9]{2})\d{18}$/, + MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{12}$/, + MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/, + NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/, + NO: /^(NO[0-9]{2})\d{11}$/, + PL: /^(PL[0-9]{2})\d{24}$/, + PS: /^(PS[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/, + PT: /^(PT[0-9]{2})\d{21}$/, + QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/, + RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/, + SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/, + SE: /^(SE[0-9]{2})\d{20}$/, + SI: /^(SI[0-9]{2})\d{15}$/, + SK: /^(SK[0-9]{2})\d{20}$/, + SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/, + RS: /^(RS[0-9]{2})\d{18}$/, + TN: /^(TN[0-9]{2})\d{20}$/, + TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/, + UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/, + XK: /^(XK[0-9]{2})\d{16}$/ +}; +/* eslint-enable max-len */ + +/** + * @function IbanCalcul - calculate if the IBAN corresponds to the reglementation: converting + * it into an integer and performing a basic mod-97 operation. If the IBAN is valid, the remainder + * equals 1. + * 1- Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid + * 2- Move the four initial characters to the end of the string + * 3- Replace each letter in the string with two digits, thereby expanding the string, + * where A = 10..., Z = 35 + * 4- Interpret the string as a decimal integer and compute the remainder of that number on + * division by 97 + * @param {e} - recieves the IBAN tested + * @warns IBAN's length differs from country to another, the maximum length is 34 characters so + * calculating its modulus 97 is not possible for all machines.To solve this, the function calculate + * the modulus of the first 9 digit by 97 and add the result to the beginning of the remain IBAN + * number. The process is repeated untill the result's length is less than 10 + */ + +var IbanCalcul = function IbanCalcul(e) { + var countryCode = e.slice(0, 4); + var result = e.slice(4, e.length) + countryCode; + + for (var counter = 1; counter <= Math.ceil(e.length / 10) + 1; counter++) { + var remainder = result.slice(0, 10).replace(/[A-Z]/g, function (element) { + return element.charCodeAt() - 55; + }) % 97; + result = remainder + result.slice(10); + } + + if (result === '1') return true; + return false; +}; + +function isIBAN(str, locale) { + (0, _assertString.default)(str); + str = str.toUpperCase(); + + if (locale in iban) { + return iban[locale].test(str) && IbanCalcul(str); + } else if (!locale || locale === 'any') { + locale = str.slice(0, 2); + + if (locale in iban) { + return iban[locale].test(str) && IbanCalcul(str); + } + + return false; + } + + throw new Error("Invalid locale '".concat(locale, "'")); +} + +var locales = Object.keys(iban); +exports.locales = locales; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 1d21203d9..595078add 100644 --- a/src/index.js +++ b/src/index.js @@ -95,8 +95,13 @@ import isWhitelisted from './lib/isWhitelisted'; import normalizeEmail from './lib/normalizeEmail'; +import toString from './lib/util/toString'; + +import isIBAN, { locales as isIBANLocales } from './lib/isIBAN'; + const version = '11.1.0'; + const validator = { version, toDate, @@ -178,6 +183,8 @@ const validator = { isWhitelisted, normalizeEmail, toString, + isIBAN, + isIBANLocales, }; export default validator; diff --git a/src/lib/isIBAN.js b/src/lib/isIBAN.js new file mode 100644 index 000000000..c8a30f341 --- /dev/null +++ b/src/lib/isIBAN.js @@ -0,0 +1,109 @@ +import assertString from './util/assertString'; + +/* eslint-disable max-len */ +const iban = { + AD: /^(AD[0-9]{2})\d{8}[0-9A-Z]{12}$/, + AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/, + AT: /^(AT[0-9]{2})\d{16}$/, + BA: /^(BA[0-9]{2})\d{16}$/, + BE: /^(BE[0-9]{2})\d{12}$/, + BG: /^(BG[0-9]{2})[A-Z]{4}\d{4}[A-Z0-9]{10}$/, + BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/, + BR: /^(BR[0-9]{2})\d{23}[A-Z][A-Z0-9]$/, + CH: /^(CH[0-9]{2})\d{17}$/, + CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/, + CZ: /^(CZ[0-9]{2})\d{20}$/, + DE: /^(DE[0-9]{2})\d{18}$/, + DK: /^(DK[0-9]{2})\d{14}$/, + EE: /^(EE[0-9]{2})\d{16}$/, + ES: /^(ES[0-9]{2})\d{20}$/, + FO: /^(FO[0-9]{2})\d{14}$/, + FI: /^(FI[0-9]{2})\d{14}$/, + FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/, + GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/, + GE: /^(GE[0-9]{2})[A-Z]{2}\d{16}$/, + GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/, + GL: /^(GL[0-9]{2})\d{14}$/, + GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/, + HR: /^(HR[0-9]{2})\d{17}$/, + HU: /^(HU[0-9]{2})\d{24}$/, + IE: /^(IE[0-9]{2})[A-Z]{4}\d{14}$/, + IS: /^(IS[0-9]{2})\d{22}$/, + IT: /^(IT[0-9]{2})[A-Z]\d{10}[A-Z0-9]{12}$/, + JO: /^(JO[0-9]{2})[A-Z]{4}\d{4}[A-Z0-9]{18}$/, + KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/, + KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/, + LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/, + LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/, + LT: /^(LT[0-9]{2})\d{16}$/, + LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/, + LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/, + MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/, + MD: /^(MD[0-9]{2})[A-Z]{2}[A-Z0-9]{18}$/, + ME: /^(ME[0-9]{2})\d{18}$/, + MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{12}$/, + MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/, + NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/, + NO: /^(NO[0-9]{2})\d{11}$/, + PL: /^(PL[0-9]{2})\d{24}$/, + PS: /^(PS[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/, + PT: /^(PT[0-9]{2})\d{21}$/, + QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/, + RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/, + SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/, + SE: /^(SE[0-9]{2})\d{20}$/, + SI: /^(SI[0-9]{2})\d{15}$/, + SK: /^(SK[0-9]{2})\d{20}$/, + SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/, + RS: /^(RS[0-9]{2})\d{18}$/, + TN: /^(TN[0-9]{2})\d{20}$/, + TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/, + UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/, + XK: /^(XK[0-9]{2})\d{16}$/, +}; +/* eslint-enable max-len */ + +/** + * @function IbanCalcul - calculate if the IBAN corresponds to the reglementation: converting + * it into an integer and performing a basic mod-97 operation. If the IBAN is valid, the remainder + * equals 1. + * 1- Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid + * 2- Move the four initial characters to the end of the string + * 3- Replace each letter in the string with two digits, thereby expanding the string, + * where A = 10..., Z = 35 + * 4- Interpret the string as a decimal integer and compute the remainder of that number on + * division by 97 + * @param {e} - recieves the IBAN tested + * @warns IBAN's length differs from country to another, the maximum length is 34 characters so + * calculating its modulus 97 is not possible for all machines.To solve this, the function calculate + * the modulus of the first 9 digit by 97 and add the result to the beginning of the remain IBAN + * number. The process is repeated untill the result's length is less than 10 + */ +const IbanCalcul = (e) => { + const countryCode = e.slice(0, 4); + let result = e.slice(4, e.length) + countryCode; + for (let counter = 1; counter <= Math.ceil(e.length / 10) + 1; counter++) { + let remainder = + result.slice(0, 10).replace(/[A-Z]/g, element => element.charCodeAt() - 55) % 97; + result = remainder + result.slice(10); + } + if (result === '1') return true; + return false; +}; + +export default function isIBAN(str, locale) { + assertString(str); + str = str.toUpperCase(); + if (locale in iban) { + return iban[locale].test(str) && IbanCalcul(str); + } else if (!locale || locale === 'any') { + locale = str.slice(0, 2); + if (locale in iban) { + return iban[locale].test(str) && IbanCalcul(str); + } + return false; + } + throw new Error(`Invalid locale '${locale}'`); +} + +export const locales = Object.keys(iban); diff --git a/test/validators.js b/test/validators.js index acb5ac226..6c57f7cc8 100644 --- a/test/validators.js +++ b/test/validators.js @@ -29,7 +29,8 @@ function test(options) { if (validator[options.validator](...args) !== true) { let warning = format( 'validator.%s(%s) failed but should have passed', - options.validator, args.join(', ') + options.validator, + args.join(', ') ); throw new Error(warning); } @@ -41,7 +42,8 @@ function test(options) { if (validator[options.validator](...args) !== false) { let warning = format( 'validator.%s(%s) passed but should have failed', - options.validator, args.join(', ') + options.validator, + args.join(', ') ); throw new Error(warning); } @@ -136,7 +138,6 @@ describe('Validators', () => { }); }); - it('should validate email addresses without UTF8 characters in local part', () => { test({ validator: 'isEmail', @@ -190,7 +191,7 @@ describe('Validators', () => { 'Some Name ', 'Some Name ', 'Some Name ', - '\'Foo Bar, Esq\'', + "'Foo Bar, Esq'", 'Some Name ', 'Some Middle Name ', 'Name ', @@ -317,7 +318,7 @@ describe('Validators', () => { 'http://10.0.0.0/', 'http://189.123.14.13/', 'http://duckduckgo.com/?q=%2F', - 'http://foobar.com/t$-_.+!*\'(),', + "http://foobar.com/t$-_.+!*'(),", 'http://foobar.com/?foo=bar#baz=qux', 'http://foobar.com?foo=bar', 'http://foobar.com#baz=qux', @@ -376,7 +377,7 @@ describe('Validators', () => { 'http://localhost:61500this is an invalid url!!!!', '////foobar.com', 'http:////foobar.com', - 'https://example.com/foo//', + "https://example.com/foo//", ], }); }); @@ -384,61 +385,52 @@ describe('Validators', () => { it('should validate URLs with custom protocols', () => { test({ validator: 'isURL', - args: [{ - protocols: ['rtmp'], - }], - valid: [ - 'rtmp://foobar.com', - ], - invalid: [ - 'http://foobar.com', + args: [ + { + protocols: ['rtmp'], + }, ], + valid: ['rtmp://foobar.com'], + invalid: ['http://foobar.com'], }); }); it('should validate file URLs without a host', () => { test({ validator: 'isURL', - args: [{ - protocols: ['file'], - require_host: false, - require_tld: false, - }], - valid: [ - 'file://localhost/foo.txt', - 'file:///foo.txt', - 'file:///', - ], - invalid: [ - 'http://foobar.com', - 'file://', + args: [ + { + protocols: ['file'], + require_host: false, + require_tld: false, + }, ], + valid: ['file://localhost/foo.txt', 'file:///foo.txt', 'file:///'], + invalid: ['http://foobar.com', 'file://'], }); }); it('should validate URLs with any protocol', () => { test({ validator: 'isURL', - args: [{ - require_valid_protocol: false, - }], - valid: [ - 'rtmp://foobar.com', - 'http://foobar.com', - 'test://foobar.com', - ], - invalid: [ - 'mailto:test@example.com', + args: [ + { + require_valid_protocol: false, + }, ], + valid: ['rtmp://foobar.com', 'http://foobar.com', 'test://foobar.com'], + invalid: ['mailto:test@example.com'], }); }); it('should validate URLs with underscores', () => { test({ validator: 'isURL', - args: [{ - allow_underscores: true, - }], + args: [ + { + allow_underscores: true, + }, + ], valid: [ 'http://foo_bar.com', 'http://pr.example_com.294.example.com/', @@ -451,16 +443,12 @@ describe('Validators', () => { it('should validate URLs that do not have a TLD', () => { test({ validator: 'isURL', - args: [{ - require_tld: false, - }], - valid: [ - 'http://foobar.com/', - 'http://foobar/', - 'http://localhost/', - 'foobar/', - 'foobar', + args: [ + { + require_tld: false, + }, ], + valid: ['http://foobar.com/', 'http://foobar/', 'http://localhost/', 'foobar/', 'foobar'], invalid: [], }); }); @@ -468,97 +456,77 @@ describe('Validators', () => { it('should validate URLs with a trailing dot option', () => { test({ validator: 'isURL', - args: [{ - allow_trailing_dot: true, - require_tld: false, - }], - valid: [ - 'http://example.com.', - 'foobar.', + args: [ + { + allow_trailing_dot: true, + require_tld: false, + }, ], + valid: ['http://example.com.', 'foobar.'], }); }); it('should validate protocol relative URLs', () => { test({ validator: 'isURL', - args: [{ - allow_protocol_relative_urls: true, - }], - valid: [ - '//foobar.com', - 'http://foobar.com', - 'foobar.com', - ], - invalid: [ - '://foobar.com', - '/foobar.com', - '////foobar.com', - 'http:////foobar.com', + args: [ + { + allow_protocol_relative_urls: true, + }, ], + valid: ['//foobar.com', 'http://foobar.com', 'foobar.com'], + invalid: ['://foobar.com', '/foobar.com', '////foobar.com', 'http:////foobar.com'], }); }); it('should not validate protocol relative URLs when require protocol is true', () => { test({ validator: 'isURL', - args: [{ - allow_protocol_relative_urls: true, - require_protocol: true, - }], - valid: [ - 'http://foobar.com', - ], - invalid: [ - '//foobar.com', - '://foobar.com', - '/foobar.com', - 'foobar.com', + args: [ + { + allow_protocol_relative_urls: true, + require_protocol: true, + }, ], + valid: ['http://foobar.com'], + invalid: ['//foobar.com', '://foobar.com', '/foobar.com', 'foobar.com'], }); }); it('should let users specify whether URLs require a protocol', () => { test({ validator: 'isURL', - args: [{ - require_protocol: true, - }], - valid: [ - 'http://foobar.com/', - ], - invalid: [ - 'http://localhost/', - 'foobar.com', - 'foobar', + args: [ + { + require_protocol: true, + }, ], + valid: ['http://foobar.com/'], + invalid: ['http://localhost/', 'foobar.com', 'foobar'], }); }); it('should let users specify a host whitelist', () => { test({ validator: 'isURL', - args: [{ - host_whitelist: ['foo.com', 'bar.com'], - }], - valid: [ - 'http://bar.com/', - 'http://foo.com/', - ], - invalid: [ - 'http://foobar.com', - 'http://foo.bar.com/', - 'http://qux.com', + args: [ + { + host_whitelist: ['foo.com', 'bar.com'], + }, ], + valid: ['http://bar.com/', 'http://foo.com/'], + invalid: ['http://foobar.com', 'http://foo.bar.com/', 'http://qux.com'], }); }); it('should allow regular expressions in the host whitelist', () => { test({ validator: 'isURL', - args: [{ - host_whitelist: ['bar.com', 'foo.com', /\.foo\.com$/], - }], + args: [ + { + host_whitelist: ['bar.com', 'foo.com', /\.foo\.com$/], + }, + ], valid: [ 'http://bar.com/', 'http://foo.com/', @@ -566,43 +534,32 @@ describe('Validators', () => { 'http://cdn.foo.com/', 'http://a.b.c.foo.com/', ], - invalid: [ - 'http://foobar.com', - 'http://foo.bar.com/', - 'http://qux.com', - ], + invalid: ['http://foobar.com', 'http://foo.bar.com/', 'http://qux.com'], }); }); it('should let users specify a host blacklist', () => { test({ validator: 'isURL', - args: [{ - host_blacklist: ['foo.com', 'bar.com'], - }], - valid: [ - 'http://foobar.com', - 'http://foo.bar.com/', - 'http://qux.com', - ], - invalid: [ - 'http://bar.com/', - 'http://foo.com/', + args: [ + { + host_blacklist: ['foo.com', 'bar.com'], + }, ], + valid: ['http://foobar.com', 'http://foo.bar.com/', 'http://qux.com'], + invalid: ['http://bar.com/', 'http://foo.com/'], }); }); it('should allow regular expressions in the host blacklist', () => { test({ validator: 'isURL', - args: [{ - host_blacklist: ['bar.com', 'foo.com', /\.foo\.com$/], - }], - valid: [ - 'http://foobar.com', - 'http://foo.bar.com/', - 'http://qux.com', + args: [ + { + host_blacklist: ['bar.com', 'foo.com', /\.foo\.com$/], + }, ], + valid: ['http://foobar.com', 'http://foo.bar.com/', 'http://qux.com'], invalid: [ 'http://bar.com/', 'http://foo.com/', @@ -617,13 +574,8 @@ describe('Validators', () => { test({ validator: 'isURL', args: [{ disallow_auth: true }], - valid: [ - 'doe.com', - ], - invalid: [ - 'john@doe.com', - 'john:john@doe.com', - ], + valid: ['doe.com'], + invalid: ['john@doe.com', 'john:john@doe.com'], }); }); @@ -654,15 +606,12 @@ describe('Validators', () => { it('should validate MAC addresses without colons', () => { test({ validator: 'isMACAddress', - args: [{ - no_colons: true, - }], - valid: [ - 'abababababab', - 'FFFFFFFFFFFF', - '0102030405ab', - '01AB03040506', + args: [ + { + no_colons: true, + }, ], + valid: ['abababababab', 'FFFFFFFFFFFF', '0102030405ab', '01AB03040506'], invalid: [ 'abc', '01:02:03:04:05', @@ -729,33 +678,14 @@ describe('Validators', () => { test({ validator: 'isIP', args: [4], - valid: [ - '127.0.0.1', - '0.0.0.0', - '255.255.255.255', - '1.2.3.4', - ], - invalid: [ - '::1', - '2001:db8:0000:1:1:1:1:1', - '::ffff:127.0.0.1', - ], + valid: ['127.0.0.1', '0.0.0.0', '255.255.255.255', '1.2.3.4'], + invalid: ['::1', '2001:db8:0000:1:1:1:1:1', '::ffff:127.0.0.1'], }); test({ validator: 'isIP', args: [6], - valid: [ - '::1', - '2001:db8:0000:1:1:1:1:1', - '::ffff:127.0.0.1', - ], - invalid: [ - '127.0.0.1', - '0.0.0.0', - '255.255.255.255', - '1.2.3.4', - '::ffff:287.0.0.1', - ], + valid: ['::1', '2001:db8:0000:1:1:1:1:1', '::ffff:127.0.0.1'], + invalid: ['127.0.0.1', '0.0.0.0', '255.255.255.255', '1.2.3.4', '::ffff:287.0.0.1'], }); test({ validator: 'isIP', @@ -775,11 +705,7 @@ describe('Validators', () => { it('should validate isIPRange', () => { test({ validator: 'isIPRange', - valid: [ - '127.0.0.1/24', - '0.0.0.0/0', - '255.255.255.0/32', - ], + valid: ['127.0.0.1/24', '0.0.0.0/0', '255.255.255.0/32'], invalid: [ '127.200.230.1/35', '127.200.230.1/-1', @@ -806,46 +732,22 @@ describe('Validators', () => { 'xn--froschgrn-x9a.com', 'rebecca.blackfriday', ], - invalid: [ - 'abc', - '256.0.0.0', - '_.com', - '*.some.com', - 's!ome.com', - 'domain.com/', - '/more.com', - ], + invalid: ['abc', '256.0.0.0', '_.com', '*.some.com', 's!ome.com', 'domain.com/', '/more.com'], }); }); it('should validate FQDN with trailing dot option', () => { test({ validator: 'isFQDN', - args: [ - { allow_trailing_dot: true }, - ], - valid: [ - 'example.com.', - ], + args: [{ allow_trailing_dot: true }], + valid: ['example.com.'], }); }); it('should validate alpha strings', () => { test({ validator: 'isAlpha', - valid: [ - 'abc', - 'ABC', - 'FoObar', - ], - invalid: [ - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], + valid: ['abc', 'ABC', 'FoObar'], + invalid: ['abc1', ' foo ', '', 'ÄBC', 'FÜübar', 'Jön', 'Heiß'], }); }); @@ -853,20 +755,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['bg-BG'], - valid: [ - 'абв', - 'АБВ', - 'жаба', - 'яГоДа', - ], - invalid: [ - 'abc1', - ' foo ', - '', - 'ЁЧПС', - '_аз_обичам_обувки_', - 'ехо!', - ], + valid: ['абв', 'АБВ', 'жаба', 'яГоДа'], + invalid: ['abc1', ' foo ', '', 'ЁЧПС', '_аз_обичам_обувки_', 'ехо!'], }); }); @@ -874,18 +764,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['cs-CZ'], - valid: [ - 'žluťoučký', - 'KŮŇ', - 'Pěl', - 'Ďábelské', - 'ódy', - ], - invalid: [ - 'ábc1', - ' fůj ', - '', - ], + valid: ['žluťoučký', 'KŮŇ', 'Pěl', 'Ďábelské', 'ódy'], + invalid: ['ábc1', ' fůj ', ''], }); }); @@ -905,12 +785,7 @@ describe('Validators', () => { 'Ďábelské', 'ódy', ], - invalid: [ - '1moj', - '你好世界', - ' Привет мир ', - 'مرحبا العا ', - ], + invalid: ['1moj', '你好世界', ' Привет мир ', 'مرحبا العا '], }); }); @@ -918,17 +793,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['da-DK'], - valid: [ - 'aøå', - 'Ære', - 'Øre', - 'Åre', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - '', - ], + valid: ['aøå', 'Ære', 'Øre', 'Åre'], + invalid: ['äbc123', 'ÄBC11', ''], }); }); @@ -936,18 +802,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['nl-NL'], - valid: [ - 'Kán', - 'één', - 'vóór', - 'nú', - 'héél', - ], - invalid: [ - 'äca ', - 'abcß', - 'Øre', - ], + valid: ['Kán', 'één', 'vóór', 'nú', 'héél'], + invalid: ['äca ', 'abcß', 'Øre'], }); }); @@ -955,17 +811,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['de-DE'], - valid: [ - 'äbc', - 'ÄBC', - 'FöÖbär', - 'Heiß', - ], - invalid: [ - 'äbc1', - ' föö ', - '', - ], + valid: ['äbc', 'ÄBC', 'FöÖbär', 'Heiß'], + invalid: ['äbc1', ' föö ', ''], }); }); @@ -973,16 +820,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['hu-HU'], - valid: [ - 'árvíztűrőtükörfúrógép', - 'ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP', - ], - invalid: [ - 'äbc1', - ' fäö ', - 'Heiß', - '', - ], + valid: ['árvíztűrőtükörfúrógép', 'ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP'], + invalid: ['äbc1', ' fäö ', 'Heiß', ''], }); }); @@ -1000,12 +839,7 @@ describe('Validators', () => { 'PÉSCA', 'genî', ], - invalid: [ - 'äbc123', - 'ÄBC11', - 'æøå', - '', - ], + invalid: ['äbc123', 'ÄBC11', 'æøå', ''], }); }); @@ -1013,21 +847,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['ar'], - valid: [ - 'أبت', - 'اَبِتَثّجً', - ], - invalid: [ - '١٢٣أبت', - '١٢٣', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], + valid: ['أبت', 'اَبِتَثّجً'], + invalid: ['١٢٣أبت', '١٢٣', 'abc1', ' foo ', '', 'ÄBC', 'FÜübar', 'Jön', 'Heiß'], }); }); @@ -1035,21 +856,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['ku-IQ'], - valid: [ - 'ئؤڤگێ', - 'کوردستان', - ], - invalid: [ - 'ئؤڤگێ١٢٣', - '١٢٣', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], + valid: ['ئؤڤگێ', 'کوردستان'], + invalid: ['ئؤڤگێ١٢٣', '١٢٣', 'abc1', ' foo ', '', 'ÄBC', 'FÜübar', 'Jön', 'Heiß'], }); }); @@ -1057,17 +865,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['nb-NO'], - valid: [ - 'aøå', - 'Ære', - 'Øre', - 'Åre', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - '', - ], + valid: ['aøå', 'Ære', 'Øre', 'Åre'], + invalid: ['äbc123', 'ÄBC11', ''], }); }); @@ -1075,20 +874,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['pl-PL'], - valid: [ - 'kreską', - 'zamknięte', - 'zwykłe', - 'kropką', - 'przyjęły', - 'święty', - 'Pozwól', - ], - invalid: [ - '12řiď ', - 'blé!!', - 'föö!2!', - ], + valid: ['kreską', 'zamknięte', 'zwykłe', 'kropką', 'przyjęły', 'święty', 'Pozwól'], + invalid: ['12řiď ', 'blé!!', 'föö!2!'], }); }); @@ -1096,15 +883,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['sr-RS'], - valid: [ - 'ШћжЂљЕ', - 'ЧПСТЋЏ', - ], - invalid: [ - 'řiď ', - 'blé33!!', - 'föö!!', - ], + valid: ['ШћжЂљЕ', 'ЧПСТЋЏ'], + invalid: ['řiď ', 'blé33!!', 'föö!!'], }); }); @@ -1112,15 +892,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['sr-RS@latin'], - valid: [ - 'ŠAabčšđćž', - 'ŠATROĆčđš', - ], - invalid: [ - '12řiď ', - 'blé!!', - 'föö!2!', - ], + valid: ['ŠAabčšđćž', 'ŠATROĆčđš'], + invalid: ['12řiď ', 'blé!!', 'föö!2!'], }); }); @@ -1128,18 +901,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['es-ES'], - valid: [ - 'ábcó', - 'ÁBCÓ', - 'dormís', - 'volvés', - 'español', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], + valid: ['ábcó', 'ÁBCÓ', 'dormís', 'volvés', 'español'], + invalid: ['äca ', 'abcß', 'föö!!'], }); }); @@ -1147,17 +910,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['sv-SE'], - valid: [ - 'religiös', - 'stjäla', - 'västgöte', - 'Åre', - ], - invalid: [ - 'AİıÖöÇ窺ĞğÜüZ', - 'religiös23', - '', - ], + valid: ['religiös', 'stjäla', 'västgöte', 'Åre'], + invalid: ['AİıÖöÇ窺ĞğÜüZ', 'religiös23', ''], }); }); @@ -1165,21 +919,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['ar-SY'], - valid: [ - 'أبت', - 'اَبِتَثّجً', - ], - invalid: [ - '١٢٣أبت', - '١٢٣', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], + valid: ['أبت', 'اَبِتَثّجً'], + invalid: ['١٢٣أبت', '١٢٣', 'abc1', ' foo ', '', 'ÄBC', 'FÜübar', 'Jön', 'Heiß'], }); }); @@ -1187,18 +928,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['tr-TR'], - valid: [ - 'AİıÖöÇ窺ĞğÜüZ', - ], - invalid: [ - '0AİıÖöÇ窺ĞğÜüZ1', - ' AİıÖöÇ窺ĞğÜüZ ', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'Heiß', - ], + valid: ['AİıÖöÇ窺ĞğÜüZ'], + invalid: ['0AİıÖöÇ窺ĞğÜüZ1', ' AİıÖöÇ窺ĞğÜüZ ', 'abc1', ' foo ', '', 'ÄBC', 'Heiß'], }); }); @@ -1206,9 +937,7 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['uk-UA'], - valid: [ - 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ', - ], + valid: ['АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ'], invalid: [ '0AİıÖöÇ窺ĞğÜüZ1', ' AİıÖöÇ窺ĞğÜüZ ', @@ -1226,19 +955,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['el-GR'], - valid: [ - 'αβγδεζηθικλμνξοπρςστυφχψω', - 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', - ], - invalid: [ - '0AİıÖöÇ窺ĞğÜüZ1', - ' AİıÖöÇ窺ĞğÜüZ ', - 'ÄBC', - 'Heiß', - 'ЫыЪъЭэ', - '120', - 'jαckγ', - ], + valid: ['αβγδεζηθικλμνξοπρςστυφχψω', 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ'], + invalid: ['0AİıÖöÇ窺ĞğÜüZ1', ' AİıÖöÇ窺ĞğÜüZ ', 'ÄBC', 'Heiß', 'ЫыЪъЭэ', '120', 'jαckγ'], }); }); @@ -1256,17 +974,8 @@ describe('Validators', () => { it('should validate alphanumeric strings', () => { test({ validator: 'isAlphanumeric', - valid: [ - 'abc123', - 'ABC11', - ], - invalid: [ - 'abc ', - 'foo!!', - 'ÄBC', - 'FÜübar', - 'Jön', - ], + valid: ['abc123', 'ABC11'], + invalid: ['abc ', 'foo!!', 'ÄBC', 'FÜübar', 'Jön'], }); }); @@ -1274,17 +983,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['en-GB'], - valid: [ - 'abc123', - 'ABC11', - ], - invalid: [ - 'abc ', - 'foo!!', - 'ÄBC', - 'FÜübar', - 'Jön', - ], + valid: ['abc123', 'ABC11'], + invalid: ['abc ', 'foo!!', 'ÄBC', 'FÜübar', 'Jön'], }); }); @@ -1292,19 +992,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['bg-BG'], - valid: [ - 'абв1', - '4АБ5В6', - 'жаба', - 'яГоДа2', - 'йЮя', - '123', - ], - invalid: [ - ' ', - '789 ', - 'hello000', - ], + valid: ['абв1', '4АБ5В6', 'жаба', 'яГоДа2', 'йЮя', '123'], + invalid: [' ', '789 ', 'hello000'], }); }); @@ -1312,14 +1001,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['cs-CZ'], - valid: [ - 'řiť123', - 'KŮŇ11', - ], - invalid: [ - 'řiď ', - 'blé!!', - ], + valid: ['řiť123', 'KŮŇ11'], + invalid: ['řiď ', 'blé!!'], }); }); @@ -1339,11 +1022,7 @@ describe('Validators', () => { '9Ďábelské', '10ódy', ], - invalid: [ - '1moj!', - '你好世界', - ' Привет мир ', - ], + invalid: ['1moj!', '你好世界', ' Привет мир '], }); }); @@ -1351,17 +1030,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['da-DK'], - valid: [ - 'ÆØÅ123', - 'Ære321', - '321Øre', - '123Åre', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - '', - ], + valid: ['ÆØÅ123', 'Ære321', '321Øre', '123Åre'], + invalid: ['äbc123', 'ÄBC11', ''], }); }); @@ -1369,18 +1039,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['nl-NL'], - valid: [ - 'Kán123', - 'één354', - 'v4óór', - 'nú234', - 'hé54él', - ], - invalid: [ - '1äca ', - 'ab3cß', - 'Øre', - ], + valid: ['Kán123', 'één354', 'v4óór', 'nú234', 'hé54él'], + invalid: ['1äca ', 'ab3cß', 'Øre'], }); }); @@ -1388,14 +1048,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['de-DE'], - valid: [ - 'äbc123', - 'ÄBC11', - ], - invalid: [ - 'äca ', - 'föö!!', - ], + valid: ['äbc123', 'ÄBC11'], + invalid: ['äca ', 'föö!!'], }); }); @@ -1403,17 +1057,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['hu-HU'], - valid: [ - '0árvíztűrőtükörfúrógép123', - '0ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP123', - ], - invalid: [ - '1időúr!', - 'äbc1', - ' fäö ', - 'Heiß!', - '', - ], + valid: ['0árvíztűrőtükörfúrógép123', '0ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP123'], + invalid: ['1időúr!', 'äbc1', ' fäö ', 'Heiß!', ''], }); }); @@ -1431,12 +1076,7 @@ describe('Validators', () => { 'PÉS45CA', 'gen45î', ], - invalid: [ - 'äbc123', - 'ÄBC11', - 'æøå', - '', - ], + invalid: ['äbc123', 'ÄBC11', 'æøå', ''], }); }); @@ -1444,15 +1084,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['es-ES'], - valid: [ - 'ábcó123', - 'ÁBCÓ11', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], + valid: ['ábcó123', 'ÁBCÓ11'], + invalid: ['äca ', 'abcß', 'föö!!'], }); }); @@ -1460,15 +1093,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['ar'], - valid: [ - 'أبت123', - 'أبتَُِ١٢٣', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], + valid: ['أبت123', 'أبتَُِ١٢٣'], + invalid: ['äca ', 'abcß', 'föö!!'], }); }); @@ -1476,14 +1102,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['ku-IQ'], - valid: [ - 'ئؤڤگێ١٢٣', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], + valid: ['ئؤڤگێ١٢٣'], + invalid: ['äca ', 'abcß', 'föö!!'], }); }); @@ -1491,17 +1111,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['ar-SY'], - valid: [ - 'أبت123', - 'أبتَُِ١٢٣', - ], - invalid: [ - 'abc ', - 'foo!!', - 'ÄBC', - 'FÜübar', - 'Jön', - ], + valid: ['أبت123', 'أبتَُِ١٢٣'], + invalid: ['abc ', 'foo!!', 'ÄBC', 'FÜübar', 'Jön'], }); }); @@ -1509,17 +1120,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['nb-NO'], - valid: [ - 'ÆØÅ123', - 'Ære321', - '321Øre', - '123Åre', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - '', - ], + valid: ['ÆØÅ123', 'Ære321', '321Øre', '123Åre'], + invalid: ['äbc123', 'ÄBC11', ''], }); }); @@ -1536,11 +1138,7 @@ describe('Validators', () => { 'świ23ęty', 'Poz1322wól', ], - invalid: [ - '12řiď ', - 'blé!!', - 'föö!2!', - ], + invalid: ['12řiď ', 'blé!!', 'föö!2!'], }); }); @@ -1548,15 +1146,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['sr-RS'], - valid: [ - 'ШћжЂљЕ123', - 'ЧПСТ132ЋЏ', - ], - invalid: [ - 'řiď ', - 'blé!!', - 'föö!!', - ], + valid: ['ШћжЂљЕ123', 'ЧПСТ132ЋЏ'], + invalid: ['řiď ', 'blé!!', 'föö!!'], }); }); @@ -1564,15 +1155,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['sr-RS@latin'], - valid: [ - 'ŠAabčšđćž123', - 'ŠATRO11Ćčđš', - ], - invalid: [ - 'řiď ', - 'blé!!', - 'föö!!', - ], + valid: ['ŠAabčšđćž123', 'ŠATRO11Ćčđš'], + invalid: ['řiď ', 'blé!!', 'föö!!'], }); }); @@ -1580,17 +1164,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['sv-SE'], - valid: [ - 'religiös13', - 'st23jäla', - 'västgöte123', - '123Åre', - ], - invalid: [ - 'AİıÖöÇ窺ĞğÜüZ', - 'foo!!', - '', - ], + valid: ['religiös13', 'st23jäla', 'västgöte123', '123Åre'], + invalid: ['AİıÖöÇ窺ĞğÜüZ', 'foo!!', ''], }); }); @@ -1598,14 +1173,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['tr-TR'], - valid: [ - 'AİıÖöÇ窺ĞğÜüZ123', - ], - invalid: [ - 'AİıÖöÇ窺ĞğÜüZ ', - 'foo!!', - 'ÄBC', - ], + valid: ['AİıÖöÇ窺ĞğÜüZ123'], + invalid: ['AİıÖöÇ窺ĞğÜüZ ', 'foo!!', 'ÄBC'], }); }); @@ -1613,15 +1182,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['uk-UA'], - valid: [ - 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ123', - ], - invalid: [ - 'éeoc ', - 'foo!!', - 'ÄBC', - 'ЫыЪъЭэ', - ], + valid: ['АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ123'], + invalid: ['éeoc ', 'foo!!', 'ÄBC', 'ЫыЪъЭэ'], }); }); @@ -1629,20 +1191,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['el-GR'], - valid: [ - 'αβγδεζηθικλμνξοπρςστυφχψω', - 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', - '20θ', - '1234568960', - ], - invalid: [ - '0AİıÖöÇ窺ĞğÜüZ1', - ' AİıÖöÇ窺ĞğÜüZ ', - 'ÄBC', - 'Heiß', - 'ЫыЪъЭэ', - 'jαckγ', - ], + valid: ['αβγδεζηθικλμνξοπρςστυφχψω', 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', '20θ', '1234568960'], + invalid: ['0AİıÖöÇ窺ĞğÜüZ1', ' AİıÖöÇ窺ĞğÜüZ ', 'ÄBC', 'Heiß', 'ЫыЪъЭэ', 'jαckγ'], }); }); @@ -1660,65 +1210,29 @@ describe('Validators', () => { it('should validate numeric strings', () => { test({ validator: 'isNumeric', - valid: [ - '123', - '00123', - '-00123', - '0', - '-0', - '+123', - '123.123', - '+000000', - ], - invalid: [ - ' ', - '', - '.', - ], + valid: ['123', '00123', '-00123', '0', '-0', '+123', '123.123', '+000000'], + invalid: [' ', '', '.'], }); }); it('should validate numeric strings without symbols', () => { test({ validator: 'isNumeric', - args: [{ - no_symbols: true, - }], - valid: [ - '123', - '00123', - '0', - ], - invalid: [ - '-0', - '+000000', - '', - '+123', - '123.123', - '-00123', - ' ', - '.', + args: [ + { + no_symbols: true, + }, ], + valid: ['123', '00123', '0'], + invalid: ['-0', '+000000', '', '+123', '123.123', '-00123', ' ', '.'], }); }); it('should validate ports', () => { test({ validator: 'isPort', - valid: [ - '0', - '22', - '80', - '443', - '3000', - '8080', - '65535', - ], - invalid: [ - '', - '-1', - '65536', - ], + valid: ['0', '22', '80', '443', '3000', '8080', '65535'], + invalid: ['', '-1', '65536'], }); }); @@ -1947,13 +1461,7 @@ describe('Validators', () => { test({ validator: 'isDecimal', args: [{ force_decimal: true }], - valid: [ - '0.01', - '.1', - '1.0', - '-.25', - '0.0000000000001', - ], + valid: ['0.01', '.1', '1.0', '-.25', '0.0000000000001'], invalid: [ '-0', '123', @@ -1982,19 +1490,7 @@ describe('Validators', () => { test({ validator: 'isDecimal', args: [{ decimal_digits: '2,3' }], - valid: [ - '123', - '00123', - '-00123', - '0', - '-0', - '+123', - '0.01', - '1.043', - '.15', - '-.255', - '-0', - ], + valid: ['123', '00123', '-00123', '0', '-0', '+123', '0.01', '1.043', '.15', '-.255', '-0'], invalid: [ '0.0000000000001', '0.0', @@ -2034,156 +1530,68 @@ describe('Validators', () => { it('should validate lowercase strings', () => { test({ validator: 'isLowercase', - valid: [ - 'abc', - 'abc123', - 'this is lowercase.', - 'tr竪s 端ber', - ], - invalid: [ - 'fooBar', - '123A', - ], + valid: ['abc', 'abc123', 'this is lowercase.', 'tr竪s 端ber'], + invalid: ['fooBar', '123A'], }); }); it('should validate uppercase strings', () => { test({ validator: 'isUppercase', - valid: [ - 'ABC', - 'ABC123', - 'ALL CAPS IS FUN.', - ' .', - ], - invalid: [ - 'fooBar', - '123abc', - ], + valid: ['ABC', 'ABC123', 'ALL CAPS IS FUN.', ' .'], + invalid: ['fooBar', '123abc'], }); }); it('should validate integers', () => { test({ validator: 'isInt', - valid: [ - '13', - '123', - '0', - '123', - '-0', - '+1', - '01', - '-01', - '000', - ], - invalid: [ - '100e10', - '123.123', - ' ', - '', - ], + valid: ['13', '123', '0', '123', '-0', '+1', '01', '-01', '000'], + invalid: ['100e10', '123.123', ' ', ''], }); test({ validator: 'isInt', args: [{ allow_leading_zeroes: false }], - valid: [ - '13', - '123', - '0', - '123', - '-0', - '+1', - ], - invalid: [ - '01', - '-01', - '000', - '100e10', - '123.123', - ' ', - '', - ], + valid: ['13', '123', '0', '123', '-0', '+1'], + invalid: ['01', '-01', '000', '100e10', '123.123', ' ', ''], }); test({ validator: 'isInt', args: [{ allow_leading_zeroes: true }], - valid: [ - '13', - '123', - '0', - '123', - '-0', - '+1', - '01', - '-01', - '000', - '-000', - '+000', - ], - invalid: [ - '100e10', - '123.123', - ' ', - '', - ], + valid: ['13', '123', '0', '123', '-0', '+1', '01', '-01', '000', '-000', '+000'], + invalid: ['100e10', '123.123', ' ', ''], }); test({ validator: 'isInt', - args: [{ - min: 10, - }], - valid: [ - '15', - '80', - '99', - ], - invalid: [ - '9', - '6', - '3.2', - 'a', + args: [ + { + min: 10, + }, ], + valid: ['15', '80', '99'], + invalid: ['9', '6', '3.2', 'a'], }); test({ validator: 'isInt', - args: [{ - min: 10, - max: 15, - }], - valid: [ - '15', - '11', - '13', - ], - invalid: [ - '9', - '2', - '17', - '3.2', - '33', - 'a', + args: [ + { + min: 10, + max: 15, + }, ], + valid: ['15', '11', '13'], + invalid: ['9', '2', '17', '3.2', '33', 'a'], }); test({ validator: 'isInt', - args: [{ - gt: 10, - lt: 15, - }], - valid: [ - '14', - '11', - '13', - ], - invalid: [ - '10', - '15', - '17', - '3.2', - '33', - 'a', + args: [ + { + gt: 10, + lt: 15, + }, ], + valid: ['14', '11', '13'], + invalid: ['10', '15', '17', '3.2', '33', 'a'], }); }); @@ -2204,14 +1612,7 @@ describe('Validators', () => { '01.123', '-0.22250738585072011e-307', ], - invalid: [ - '+', - '-', - ' ', - '', - '.', - 'foo', - ], + invalid: ['+', '-', ' ', '', '.', 'foo'], }); test({ @@ -2231,14 +1632,7 @@ describe('Validators', () => { '01.123', '-0.22250738585072011e-307', ], - invalid: [ - '123٫123', - '123,123', - ' ', - '', - '.', - 'foo', - ], + invalid: ['123٫123', '123,123', ' ', '', '.', 'foo'], }); test({ @@ -2258,14 +1652,7 @@ describe('Validators', () => { '01,123', '-0,22250738585072011e-307', ], - invalid: [ - '123.123', - '123٫123', - ' ', - '', - '.', - 'foo', - ], + invalid: ['123.123', '123٫123', ' ', '', '.', 'foo'], }); test({ @@ -2285,113 +1672,63 @@ describe('Validators', () => { '01٫123', '-0٫22250738585072011e-307', ], - invalid: [ - '123,123', - '123.123', - ' ', - '', - '.', - 'foo', - ], + invalid: ['123,123', '123.123', ' ', '', '.', 'foo'], }); test({ validator: 'isFloat', - args: [{ - min: 3.7, - }], - valid: [ - '3.888', - '3.92', - '4.5', - '50', - '3.7', - '3.71', - ], - invalid: [ - '3.6', - '3.69', - '3', - '1.5', - 'a', + args: [ + { + min: 3.7, + }, ], + valid: ['3.888', '3.92', '4.5', '50', '3.7', '3.71'], + invalid: ['3.6', '3.69', '3', '1.5', 'a'], }); test({ validator: 'isFloat', - args: [{ - min: 0.1, - max: 1.0, - }], - valid: [ - '0.1', - '1.0', - '0.15', - '0.33', - '0.57', - '0.7', - ], - invalid: [ - '0', - '0.0', - 'a', - '1.3', - '0.05', - '5', + args: [ + { + min: 0.1, + max: 1.0, + }, ], + valid: ['0.1', '1.0', '0.15', '0.33', '0.57', '0.7'], + invalid: ['0', '0.0', 'a', '1.3', '0.05', '5'], }); test({ validator: 'isFloat', - args: [{ - gt: -5.5, - lt: 10, - }], - valid: [ - '9.9', - '1.0', - '0', - '-1', - '7', - '-5.4', - ], - invalid: [ - '10', - '-5.5', - 'a', - '-20.3', - '20e3', - '10.00001', + args: [ + { + gt: -5.5, + lt: 10, + }, ], + valid: ['9.9', '1.0', '0', '-1', '7', '-5.4'], + invalid: ['10', '-5.5', 'a', '-20.3', '20e3', '10.00001'], }); test({ validator: 'isFloat', - args: [{ - min: -5.5, - max: 10, - gt: -5.5, - lt: 10, - }], - valid: [ - '9.99999', - '-5.499999', - ], - invalid: [ - '10', - '-5.5', + args: [ + { + min: -5.5, + max: 10, + gt: -5.5, + lt: 10, + }, ], + valid: ['9.99999', '-5.499999'], + invalid: ['10', '-5.5'], }); test({ validator: 'isFloat', - args: [{ - locale: 'de-DE', - min: 3.1, - }], - valid: [ - '123', - '123,', - '123,123', - '3,1', - '3,100001', + args: [ + { + locale: 'de-DE', + min: 3.1, + }, ], + valid: ['123', '123,', '123,123', '3,1', '3,100001'], invalid: [ '3,09', '-,123', @@ -2416,50 +1753,24 @@ describe('Validators', () => { it('should validate hexadecimal strings', () => { test({ validator: 'isHexadecimal', - valid: [ - 'deadBEEF', - 'ff0044', - ], - invalid: [ - 'abcdefg', - '', - '..', - ], + valid: ['deadBEEF', 'ff0044'], + invalid: ['abcdefg', '', '..'], }); }); it('should validate hexadecimal color strings', () => { test({ validator: 'isHexColor', - valid: [ - '#ff0034', - '#CCCCCC', - 'fff', - '#f00', - ], - invalid: [ - '#ff', - 'fff0', - '#ff12FG', - ], + valid: ['#ff0034', '#CCCCCC', 'fff', '#f00'], + invalid: ['#ff', 'fff0', '#ff12FG'], }); }); it('should validate ISRC code strings', () => { test({ validator: 'isISRC', - valid: [ - 'USAT29900609', - 'GBAYE6800011', - 'USRC15705223', - 'USCA29500702', - ], - invalid: [ - 'USAT2990060', - 'SRC15705223', - 'US-CA29500702', - 'USARC15705223', - ], + valid: ['USAT29900609', 'GBAYE6800011', 'USRC15705223', 'USCA29500702'], + invalid: ['USAT2990060', 'SRC15705223', 'US-CA29500702', 'USARC15705223'], }); }); @@ -2472,12 +1783,7 @@ describe('Validators', () => { '88dae00e614d8f24cfd5a8b3f8002e93', '0bf1c35032a71a14c2f719e5a14c1e96', ], - invalid: [ - 'KYT0bf1c35032a71a14c2f719e5a14c1', - 'q94375dj93458w34', - '39485729348', - '%&FHKJFvk', - ], + invalid: ['KYT0bf1c35032a71a14c2f719e5a14c1', 'q94375dj93458w34', '39485729348', '%&FHKJFvk'], }); }); @@ -2634,55 +1940,36 @@ describe('Validators', () => { 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqb2huIjp7ImFnZSI6MjUsImhlaWdodCI6MTg1fSwiamFrZSI6eyJhZ2UiOjMwLCJoZWlnaHQiOjI3MH19.YRLPARDmhGMC3BBk_OhtwwK21PIkVCqQe8ncIRPKo-E', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ', // No signature ], - invalid: [ - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9', - '$Zs.ewu.su84', - 'ks64$S/9.dy$§kz.3sd73b', - ], + invalid: ['eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9', '$Zs.ewu.su84', 'ks64$S/9.dy$§kz.3sd73b'], }); }); it('should validate null strings', () => { test({ validator: 'isEmpty', - valid: [ - '', - ], - invalid: [ - ' ', - 'foo', - '3', - ], + valid: [''], + invalid: [' ', 'foo', '3'], }); test({ validator: 'isEmpty', args: [{ ignore_whitespace: false }], - valid: [ - '', - ], - invalid: [ - ' ', - 'foo', - '3', - ], + valid: [''], + invalid: [' ', 'foo', '3'], }); test({ validator: 'isEmpty', args: [{ ignore_whitespace: true }], - valid: [ - '', - ' ', - ], - invalid: [ - 'foo', - '3', - ], + valid: ['', ' '], + invalid: ['foo', '3'], }); }); it('should validate strings against an expected value', () => { test({ - validator: 'equals', args: ['abc'], valid: ['abc'], invalid: ['Abc', '123'], + validator: 'equals', + args: ['abc'], + valid: ['abc'], + invalid: ['Abc', '123'], }); }); @@ -2849,9 +2136,7 @@ describe('Validators', () => { test({ validator: 'isUUID', args: [3], - valid: [ - 'A987FBC9-4BED-3078-CF07-9141BA07C9F3', - ], + valid: ['A987FBC9-4BED-3078-CF07-9141BA07C9F3'], invalid: [ '', 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3', @@ -2982,11 +2267,7 @@ describe('Validators', () => { }); test({ validator: 'isBefore', - valid: [ - '2000-08-04', - new Date(0).toString(), - new Date(Date.now() - 86400000).toString(), - ], + valid: ['2000-08-04', new Date(0).toString(), new Date(Date.now() - 86400000).toString()], invalid: ['2100-07-02', new Date(2217, 10, 10).toString()], }); test({ @@ -3007,13 +2288,7 @@ describe('Validators', () => { validator: 'isDivisibleBy', args: [2], valid: ['2', '4', '100', '1000'], - invalid: [ - '1', - '2.5', - '101', - 'foo', - '', - ], + invalid: ['1', '2.5', '101', 'foo', ''], }); }); @@ -3172,13 +2447,8 @@ describe('Validators', () => { // Test generics test({ validator: 'isIdentityCard', - valid: [ - ...allValid, - ], - invalid: [ - 'foo', - ...allInvalid, - ], + valid: [...allValid], + invalid: ['foo', ...allInvalid], args: ['any'], }); }); @@ -3206,12 +2476,7 @@ describe('Validators', () => { 'DE000WCH8881', 'PLLWBGD00016', ], - invalid: [ - 'DE000BAY0018', - 'PLLWBGD00019', - 'foo', - '5398228707871528', - ], + invalid: ['DE000BAY0018', 'PLLWBGD00019', 'foo', '5398228707871528'], }); }); @@ -3220,64 +2485,75 @@ describe('Validators', () => { validator: 'isISBN', args: [10], valid: [ - '3836221195', '3-8362-2119-5', '3 8362 2119 5', - '1617290858', '1-61729-085-8', '1 61729 085-8', - '0007269706', '0-00-726970-6', '0 00 726970 6', - '3423214120', '3-423-21412-0', '3 423 21412 0', - '340101319X', '3-401-01319-X', '3 401 01319 X', + '3836221195', + '3-8362-2119-5', + '3 8362 2119 5', + '1617290858', + '1-61729-085-8', + '1 61729 085-8', + '0007269706', + '0-00-726970-6', + '0 00 726970 6', + '3423214120', + '3-423-21412-0', + '3 423 21412 0', + '340101319X', + '3-401-01319-X', + '3 401 01319 X', ], invalid: [ - '3423214121', '3-423-21412-1', '3 423 21412 1', - '978-3836221191', '9783836221191', - '123456789a', 'foo', '', + '3423214121', + '3-423-21412-1', + '3 423 21412 1', + '978-3836221191', + '9783836221191', + '123456789a', + 'foo', + '', ], }); test({ validator: 'isISBN', args: [13], valid: [ - '9783836221191', '978-3-8362-2119-1', '978 3 8362 2119 1', - '9783401013190', '978-3401013190', '978 3401013190', - '9784873113685', '978-4-87311-368-5', '978 4 87311 368 5', + '9783836221191', + '978-3-8362-2119-1', + '978 3 8362 2119 1', + '9783401013190', + '978-3401013190', + '978 3401013190', + '9784873113685', + '978-4-87311-368-5', + '978 4 87311 368 5', ], invalid: [ - '9783836221190', '978-3-8362-2119-0', '978 3 8362 2119 0', - '3836221195', '3-8362-2119-5', '3 8362 2119 5', - '01234567890ab', 'foo', '', + '9783836221190', + '978-3-8362-2119-0', + '978 3 8362 2119 0', + '3836221195', + '3-8362-2119-5', + '3 8362 2119 5', + '01234567890ab', + 'foo', + '', ], }); test({ validator: 'isISBN', - valid: [ - '340101319X', - '9784873113685', - ], - invalid: [ - '3423214121', - '9783836221190', - ], + valid: ['340101319X', '9784873113685'], + invalid: ['3423214121', '9783836221190'], }); test({ validator: 'isISBN', args: ['foo'], - invalid: [ - '340101319X', - '9784873113685', - ], + invalid: ['340101319X', '9784873113685'], }); }); it('should validate ISSNs', () => { test({ validator: 'isISSN', - valid: [ - '0378-5955', - '0000-0000', - '2434-561X', - '2434-561x', - '01896016', - '20905076', - ], + valid: ['0378-5955', '0000-0000', '2434-561X', '2434-561x', '01896016', '20905076'], invalid: [ '0378-5954', '0000-0001', @@ -3293,62 +2569,28 @@ describe('Validators', () => { test({ validator: 'isISSN', args: [{ case_sensitive: true }], - valid: [ - '2434-561X', - '2434561X', - '0378-5955', - '03785955', - ], - invalid: [ - '2434-561x', - '2434561x', - ], + valid: ['2434-561X', '2434561X', '0378-5955', '03785955'], + invalid: ['2434-561x', '2434561x'], }); test({ validator: 'isISSN', args: [{ require_hyphen: true }], - valid: [ - '2434-561X', - '2434-561x', - '0378-5955', - ], - invalid: [ - '2434561X', - '2434561x', - '03785955', - ], + valid: ['2434-561X', '2434-561x', '0378-5955'], + invalid: ['2434561X', '2434561x', '03785955'], }); test({ validator: 'isISSN', args: [{ case_sensitive: true, require_hyphen: true }], - valid: [ - '2434-561X', - '0378-5955', - ], - invalid: [ - '2434-561x', - '2434561X', - '2434561x', - '03785955', - ], + valid: ['2434-561X', '0378-5955'], + invalid: ['2434-561x', '2434561X', '2434561x', '03785955'], }); }); it('should validate JSON', () => { test({ validator: 'isJSON', - valid: [ - '{ "key": "value" }', - '{}', - ], - invalid: [ - '{ key: "value" }', - '{ \'key\': \'value\' }', - 'null', - '1234', - 'false', - '"nope"', - ], + valid: ['{ "key": "value" }', '{}'], + invalid: ['{ key: "value" }', "{ 'key': 'value' }", 'null', '1234', 'false', '"nope"'], }); }); @@ -3363,74 +2605,38 @@ describe('Validators', () => { 'カタカナ', '中文', ], - invalid: [ - 'abc', - 'abc123', - '<>@" *.', - ], + invalid: ['abc', 'abc123', '<>@" *.'], }); }); it('should validate ascii strings', () => { test({ validator: 'isAscii', - valid: [ - 'foobar', - '0987654321', - 'test@example.com', - '1234abcDEF', - ], - invalid: [ - 'foobar', - 'xyz098', - '123456', - 'カタカナ', - ], + valid: ['foobar', '0987654321', 'test@example.com', '1234abcDEF'], + invalid: ['foobar', 'xyz098', '123456', 'カタカナ'], }); }); it('should validate full-width strings', () => { test({ validator: 'isFullWidth', - valid: [ - 'ひらがな・カタカナ、.漢字', - '3ー0 a@com', - 'Fカタカナ゙ᆲ', - 'Good=Parts', - ], - invalid: [ - 'abc', - 'abc123', - '!"#$%&()<>/+=-_? ~^|.,@`{}[]', - ], + valid: ['ひらがな・カタカナ、.漢字', '3ー0 a@com', 'Fカタカナ゙ᆲ', 'Good=Parts'], + invalid: ['abc', 'abc123', '!"#$%&()<>/+=-_? ~^|.,@`{}[]'], }); }); it('should validate half-width strings', () => { test({ validator: 'isHalfWidth', - valid: [ - '!"#$%&()<>/+=-_? ~^|.,@`{}[]', - 'l-btn_02--active', - 'abc123い', - 'カタカナ゙ᆲ←', - ], - invalid: [ - 'あいうえお', - '0011', - ], + valid: ['!"#$%&()<>/+=-_? ~^|.,@`{}[]', 'l-btn_02--active', 'abc123い', 'カタカナ゙ᆲ←'], + invalid: ['あいうえお', '0011'], }); }); it('should validate variable-width strings', () => { test({ validator: 'isVariableWidth', - valid: [ - 'ひらがなカタカナ漢字ABCDE', - '3ー0123', - 'Fカタカナ゙ᆲ', - 'Good=Parts', - ], + valid: ['ひらがなカタカナ漢字ABCDE', '3ー0123', 'Fカタカナ゙ᆲ', 'Good=Parts'], invalid: [ 'abc', 'abc123', @@ -3445,16 +2651,8 @@ describe('Validators', () => { it('should validate surrogate pair strings', () => { test({ validator: 'isSurrogatePair', - valid: [ - '𠮷野𠮷', - '𩸽', - 'ABC千𥧄1-2-3', - ], - invalid: [ - '吉野竈', - '鮪', - 'ABC1-2-3', - ], + valid: ['𠮷野𠮷', '𩸽', 'ABC千𥧄1-2-3'], + invalid: ['吉野竈', '鮪', 'ABC1-2-3'], }); }); @@ -3517,7 +2715,7 @@ describe('Validators', () => { ], }); for (let i = 0, str = '', encoded; i < 1000; i++) { - str += String.fromCharCode(Math.random() * 26 | 97); // eslint-disable-line no-bitwise + str += String.fromCharCode((Math.random() * 26) | 97); // eslint-disable-line no-bitwise encoded = Buffer.from(str).toString('base64'); if (!validator.isBase64(encoded)) { let msg = format('validator.isBase64() failed with "%s"', encoded); @@ -3529,9 +2727,7 @@ describe('Validators', () => { it('should validate hex-encoded MongoDB ObjectId', () => { test({ validator: 'isMongoId', - valid: [ - '507f1f77bcf86cd799439011', - ], + valid: ['507f1f77bcf86cd799439011'], invalid: [ '507f1f77bcf86cd7994390', '507f1f77bcf86cd79943901z', @@ -3695,67 +2891,23 @@ describe('Validators', () => { }, { locale: 'ar-SY', - valid: [ - '0944549710', - '+963944549710', - '956654379', - '0944549710', - '0962655597', - ], - invalid: [ - '12345', - '', - '+9639626626262', - '+963332210972', - '0114152198', - ], + valid: ['0944549710', '+963944549710', '956654379', '0944549710', '0962655597'], + invalid: ['12345', '', '+9639626626262', '+963332210972', '0114152198'], }, { locale: 'ar-SA', - valid: [ - '0556578654', - '+966556578654', - '966556578654', - '596578654', - '572655597', - ], - invalid: [ - '12345', - '', - '+9665626626262', - '+96633221097', - '0114152198', - ], + valid: ['0556578654', '+966556578654', '966556578654', '596578654', '572655597'], + invalid: ['12345', '', '+9665626626262', '+96633221097', '0114152198'], }, { locale: 'ar-TN', - valid: [ - '23456789', - '+21623456789', - '21623456789', - ], - invalid: [ - '12345', - '75200123', - '+216512345678', - '13520459', - '85479520', - ], + valid: ['23456789', '+21623456789', '21623456789'], + invalid: ['12345', '75200123', '+216512345678', '13520459', '85479520'], }, { locale: 'bg-BG', - valid: [ - '+359897123456', - '+359898888888', - '0897123123', - ], - invalid: [ - '', - '0898123', - '+359212555666', - '18001234567', - '12125559999', - ], + valid: ['+359897123456', '+359898888888', '0897123123'], + invalid: ['', '0898123', '+359212555666', '18001234567', '12125559999'], }, { locale: 'bn-BD', @@ -3778,37 +2930,13 @@ describe('Validators', () => { }, { locale: 'cs-CZ', - valid: [ - '+420 123 456 789', - '+420 123456789', - '+420123456789', - '123 456 789', - '123456789', - ], - invalid: [ - '', - '+42012345678', - '+421 123 456 789', - '+420 023456789', - '+4201234567892', - ], + valid: ['+420 123 456 789', '+420 123456789', '+420123456789', '123 456 789', '123456789'], + invalid: ['', '+42012345678', '+421 123 456 789', '+420 023456789', '+4201234567892'], }, { locale: 'sk-SK', - valid: [ - '+421 123 456 789', - '+421 123456789', - '+421123456789', - '123 456 789', - '123456789', - ], - invalid: [ - '', - '+42112345678', - '+422 123 456 789', - '+421 023456789', - '+4211234567892', - ], + valid: ['+421 123 456 789', '+421 123456789', '+421123456789', '123 456 789', '123456789'], + invalid: ['', '+42112345678', '+422 123 456 789', '+421 023456789', '+4211234567892'], }, { locale: 'de-DE', @@ -3916,42 +3044,17 @@ describe('Validators', () => { }, { locale: 'zh-TW', - valid: [ - '0987123456', - '+886987123456', - '886987123456', - '+886-987123456', - '886-987123456', - ], - invalid: [ - '12345', - '', - 'Vml2YW11cyBmZXJtZtesting123', - '0-987123456', - ], + valid: ['0987123456', '+886987123456', '886987123456', '+886-987123456', '886-987123456'], + invalid: ['12345', '', 'Vml2YW11cyBmZXJtZtesting123', '0-987123456'], }, { locale: 'en-ZA', - valid: [ - '0821231234', - '+27821231234', - '27821231234', - ], - invalid: [ - '082123', - '08212312345', - '21821231234', - '+21821231234', - '+0821231234', - ], + valid: ['0821231234', '+27821231234', '27821231234'], + invalid: ['082123', '08212312345', '21821231234', '+21821231234', '+0821231234'], }, { locale: 'en-AU', - valid: [ - '61404111222', - '+61411222333', - '0417123456', - ], + valid: ['61404111222', '+61411222333', '0417123456'], invalid: [ '082123', '08212312345', @@ -3985,12 +3088,7 @@ describe('Validators', () => { '+233232345671', '+233282345671', ], - invalid: [ - '082123', - '232345671', - '0292345671', - '+233292345671', - ], + invalid: ['082123', '232345671', '0292345671', '+233292345671'], }, { locale: 'en-HK', @@ -4004,12 +3102,7 @@ describe('Validators', () => { '+852-9123-4567', '852-91234567', ], - invalid: [ - '999', - '+852-912345678', - '123456789', - '+852-1234-56789', - ], + invalid: ['999', '+852-912345678', '123456789', '+852-1234-56789'], }, { locale: 'en-IE', @@ -4024,13 +3117,7 @@ describe('Validators', () => { '0871234567', '0851234567', ], - invalid: [ - '999', - '+353341234567', - '+33589484858', - '353841234567', - '353811234567', - ], + invalid: ['999', '+353341234567', '+33589484858', '353841234567', '353811234567'], }, { locale: 'en-KE', @@ -4066,54 +3153,18 @@ describe('Validators', () => { }, { locale: 'en-UG', - valid: [ - '+256728590432', - '+256733875610', - '256728590234', - '0773346543', - '0700459022', - ], - invalid: [ - '999', - '+254728590432', - '+25489032', - '123456789', - '+254800723845', - ], + valid: ['+256728590432', '+256733875610', '256728590234', '0773346543', '0700459022'], + invalid: ['999', '+254728590432', '+25489032', '123456789', '+254800723845'], }, { locale: 'en-RW', - valid: [ - '+250728590432', - '+250733875610', - '250738590234', - '0753346543', - '0780459022', - ], - invalid: [ - '999', - '+254728590432', - '+25089032', - '123456789', - '+250800723845', - ], + valid: ['+250728590432', '+250733875610', '250738590234', '0753346543', '0780459022'], + invalid: ['999', '+254728590432', '+25089032', '123456789', '+250800723845'], }, { locale: 'en-TZ', - valid: [ - '+255728590432', - '+255733875610', - '255628590234', - '0673346543', - '0600459022', - ], - invalid: [ - '999', - '+254728590432', - '+25589032', - '123456789', - '+255800723845', - ], + valid: ['+255728590432', '+255733875610', '255628590234', '0673346543', '0600459022'], + invalid: ['999', '+254728590432', '+25589032', '123456789', '+255800723845'], }, { locale: 'fr-FR', @@ -4242,11 +3293,7 @@ describe('Validators', () => { }, { locale: 'el-GR', - valid: [ - '+306944848966', - '6944848966', - '306944848966', - ], + valid: ['+306944848966', '6944848966', '306944848966'], invalid: [ '2102323234', '+302646041461', @@ -4259,11 +3306,7 @@ describe('Validators', () => { }, { locale: 'en-GB', - valid: [ - '447789345856', - '+447861235675', - '07888814488', - ], + valid: ['447789345856', '+447861235675', '07888814488'], invalid: [ '67699567', '0773894868', @@ -4278,12 +3321,7 @@ describe('Validators', () => { }, { locale: 'en-SG', - valid: [ - '87654321', - '98765432', - '+6587654321', - '+6598765432', - ], + valid: ['87654321', '98765432', '+6587654321', '+6598765432'], invalid: [ '987654321', '876543219', @@ -4325,13 +3363,7 @@ describe('Validators', () => { { locale: 'en-CA', valid: ['19876543210', '8005552222', '+15673628910'], - invalid: [ - '564785', - '0123456789', - '1437439210', - '+10345672645', - '11435213543', - ], + invalid: ['564785', '0123456789', '1437439210', '+10345672645', '11435213543'], }, { locale: 'en-ZM', @@ -4344,22 +3376,11 @@ describe('Validators', () => { '+260976684590', '260976684590', ], - invalid: [ - '12345', - '', - 'Vml2YW11cyBmZXJtZtesting123', - '010-38238383', - '966684590', - ], + invalid: ['12345', '', 'Vml2YW11cyBmZXJtZtesting123', '010-38238383', '966684590'], }, { locale: 'ru-RU', - valid: [ - '+79676338855', - '79676338855', - '89676338855', - '9676338855', - ], + valid: ['+79676338855', '79676338855', '89676338855', '9676338855'], invalid: [ '12345', '', @@ -4394,12 +3415,7 @@ describe('Validators', () => { }, { locale: 'en-NZ', - valid: [ - '+6427987035', - '642240512347', - '0293981646', - '029968425', - ], + valid: ['+6427987035', '642240512347', '0293981646', '029968425'], invalid: [ '12345', '', @@ -4414,11 +3430,7 @@ describe('Validators', () => { }, { locale: 'en-MU', - valid: [ - '+23012341234', - '12341234', - '012341234', - ], + valid: ['+23012341234', '12341234', '012341234'], invalid: [ '41234', '', @@ -4437,14 +3449,7 @@ describe('Validators', () => { }, { locale: ['nb-NO', 'nn-NO'], // for multiple locales - valid: [ - '+4796338855', - '+4746338855', - '4796338855', - '4746338855', - '46338855', - '96338855', - ], + valid: ['+4796338855', '+4746338855', '4796338855', '4746338855', '46338855', '96338855'], invalid: [ '12345', '', @@ -4587,20 +3592,8 @@ describe('Validators', () => { }, { locale: 'es-UY', - valid: [ - '+59899123456', - '099123456', - '+59894654321', - '091111111', - ], - invalid: [ - '54321', - 'montevideo', - '', - '+598099123456', - '090883338', - '099 999 999', - ], + valid: ['+59899123456', '099123456', '+59894654321', '091111111'], + invalid: ['54321', 'montevideo', '', '+598099123456', '090883338', '099 999 999'], }, { locale: 'et-EE', @@ -4813,17 +3806,8 @@ describe('Validators', () => { }, { locale: 'it-IT', - valid: [ - '370 3175423', - '333202925', - '+39 310 7688449', - '+39 3339847632', - ], - invalid: [ - '011 7387545', - '12345', - '+45 345 6782395', - ], + valid: ['370 3175423', '333202925', '+39 310 7688449', '+39 3339847632'], + invalid: ['011 7387545', '12345', '+45 345 6782395'], }, { locale: 'fr-BE', @@ -4996,10 +3980,7 @@ describe('Validators', () => { }, { locale: 'lt-LT', - valid: [ - '+37051234567', - '851234567', - ], + valid: ['+37051234567', '851234567'], invalid: [ '+65740 123 456', '', @@ -5011,182 +3992,611 @@ describe('Validators', () => { ], }, { - locale: 'uk-UA', - valid: [ - '+380982345679', - '380982345679', - '80982345679', - '0982345679', + locale: 'uk-UA', + valid: ['+380982345679', '380982345679', '80982345679', '0982345679'], + invalid: [ + '+30982345679', + '982345679', + '+380 98 234 5679', + '+380-98-234-5679', + '', + 'ASDFGJKLmZXJtZtesting123', + '123456', + '740123456', + ], + }, + { + locale: 'da-DK', + valid: [ + '12345678', + '12 34 56 78', + '45 12345678', + '4512345678', + '45 12 34 56 78', + '+45 12 34 56 78', + ], + invalid: ['', '+45010203', 'ASDFGJKLmZXJtZtesting123', '123456', '12 34 56', '123 123 12'], + }, + { + locale: 'sv-SE', + valid: [ + '+46701234567', + '46701234567', + '0721234567', + '073-1234567', + '0761-234567', + '079-123 45 67', + ], + invalid: [ + '12345', + '+4670123456', + '+46301234567', + '+0731234567', + '0731234 56', + '+7312345678', + '', + ], + }, + { + locale: 'fo-FO', + valid: ['123456', '12 34 56', '298 123456', '298123456', '298 12 34 56', '+298 12 34 56'], + invalid: ['', '+4501020304', 'ASDFGJKLmZXJtZtesting123', '12345678', '12 34 56 78'], + }, + { + locale: 'kl-GL', + valid: ['123456', '12 34 56', '299 123456', '299123456', '299 12 34 56', '+299 12 34 56'], + invalid: ['', '+4501020304', 'ASDFGJKLmZXJtZtesting123', '12345678', '12 34 56 78'], + }, + { + locale: 'kk-KZ', + valid: ['+77254716212', '77254716212', '87254716212', '7254716212'], + invalid: [ + '12345', + '', + 'ASDFGJKLmZXJtZtesting123', + '010-38238383', + '+9676338855', + '19676338855', + '6676338855', + '+99676338855', + ], + }, + { + locale: 'be-BY', + valid: [ + '+375241234567', + '+375251234567', + '+375291234567', + '+375331234567', + '+375441234567', + '375331234567', + ], + invalid: [ + '12345', + '', + 'ASDFGJKLmZXJtZtesting123', + '010-38238383', + '+9676338855', + '19676338855', + '6676338855', + '+99676338855', + ], + }, + { + locale: 'th-TH', + valid: ['0912345678', '+66912345678', '66912345678'], + invalid: ['99123456789', '12345', '67812345623', '081234567891'], + }, + { + locale: ['en-ZA', 'be-BY'], + valid: [ + '0821231234', + '+27821231234', + '27821231234', + '+375241234567', + '+375251234567', + '+375291234567', + '+375331234567', + '+375441234567', + '375331234567', + ], + invalid: [ + '082123', + '08212312345', + '21821231234', + '+21821231234', + '+0821231234', + '12345', + '', + 'ASDFGJKLmZXJtZtesting123', + '010-38238383', + '+9676338855', + '19676338855', + '6676338855', + '+99676338855', + ], + }, + ]; + + let allValid = []; + + fixtures.forEach((fixture) => { + // to be used later on for validating 'any' locale + if (fixture.valid) allValid = allValid.concat(fixture.valid); + + if (Array.isArray(fixture.locale)) { + test({ + validator: 'isMobilePhone', + valid: fixture.valid, + invalid: fixture.invalid, + args: [fixture.locale], + }); + } else { + test({ + validator: 'isMobilePhone', + valid: fixture.valid, + invalid: fixture.invalid, + args: [fixture.locale], + }); + } + }); + + test({ + validator: 'isMobilePhone', + valid: allValid, + invalid: ['', 'asdf', '1', 'ASDFGJKLmZXJtZtesting123', 'Vml2YW11cyBmZXJtZtesting123'], + args: ['any'], + }); + + // strict mode + test({ + validator: 'isMobilePhone', + valid: ['+254728530234', '+299 12 34 56'], + invalid: ['254728530234', '0728530234', '+728530234'], + args: ['any', { strictMode: true }], + }); + + // falsey locale defaults to 'any' + test({ + validator: 'isMobilePhone', + valid: allValid, + invalid: ['', 'asdf', '1', 'ASDFGJKLmZXJtZtesting123', 'Vml2YW11cyBmZXJtZtesting123'], + args: [], + }); + }); + + it('should validate IBAN number', () => { + let fixtures = [ + { + locale: 'AD', + valid: ['AD1200012030200359100100'], + invalid: ['AD1200012030200359100109', 'AB1200012030200359100109'], + }, + { + locale: 'AL', + valid: ['AL47212110090000000235698741'], + invalid: [ + 'AL47212110090000000235698749', + 'AL472A2110090000000235698741', + 'AL472121100900000002356987419', + ], + }, + { + locale: 'AT', + valid: ['AT611904300234573201'], + invalid: ['AT611904300234573209', 'AT6119043002345732019', 'AT61190430023457320X'], + }, + { + locale: 'BH', + valid: ['BH67BMAG00001299123456'], + invalid: ['BH67BMAG00001299123451', 'BH67BM2G00001299123456', 'BH67BMAG000012991234569'], + }, + { + locale: 'BE', + valid: ['BE68539007547034'], + invalid: ['BE68539007547031', 'BE6853900754703X', 'BE685390075470349'], + }, + { + locale: 'BA', + valid: ['BA391290079401028494'], + invalid: ['BA391290079401028499', 'BA39129007940102849X', 'BA3912900794010284949'], + }, + { + locale: 'BG', + valid: ['BG80BNBG96611020345678'], + invalid: [ + 'BG80BNBG96611020345679', + 'BG80B9BG96611020345678', + 'BG80BNBG9A611020345678', + 'BG80BNBG966110203456789', + ], + }, + { + locale: 'BR', + valid: ['BR9700360305000010009795493P1'], + invalid: [ + 'BR9700360305000010009795499P1', + 'BR970036030500001000979549391', + 'BR970036030500001000979549AP1', + 'BR9700360305000010009795493P19', + ], + }, + { + locale: 'CH', + valid: ['CH9300762011623852957'], + invalid: ['CH9300762011623852959', 'CH930076201162385295A', 'CH93007620116238529579'], + }, + { + locale: 'CY', + valid: ['CY17002001280000001200527600'], + invalid: [ + 'CY17002001280000001200527609', + 'CY17A02001280000001200527600', + 'CY170020012800000012005276009', + ], + }, + { + locale: 'CZ', + valid: ['CZ6508000000192000145399'], + invalid: [ + 'CZ6508000000192000145391', + 'CZ650800000019200014539A', + 'CZ65080000001920001453999', + ], + }, + { + locale: 'DE', + valid: ['DE89370400440532013000'], + invalid: ['DE89370400440532013009', 'DE8937040044053201300A', 'DE893704004405320130009'], + }, + { + locale: 'DK', + valid: ['DK5000400440116243'], + invalid: ['DK5000400440116249', 'DK500040044011624A', 'DK50004004401162439'], + }, + { + locale: 'EE', + valid: ['EE382200221020145685'], + invalid: ['EE382200221020145689', 'EE38220022102014568A', 'EE3822002210201456859'], + }, + { + locale: 'ES', + valid: ['ES9121000418450200051332'], + invalid: [ + 'ES9121000418450200051339', + 'ES912100041845020005133A', + 'ES91210004184502000513329', + ], + }, + { + locale: 'FO', + valid: ['FO6264600001631634'], + invalid: ['FO6264600001631639', 'FO626460000163163A', 'FO62646000016316349'], + }, + { + locale: 'FI', + valid: ['FI2112345600000785'], + invalid: ['FI2112345600000789', 'FI211234560000078A', 'FI21123456000007859'], + }, + { + locale: 'FR', + valid: ['FR1420041010050500013M02606'], + invalid: [ + 'FR1420041010050500013M02609', + 'FR1420041010050500013M0260A', + 'FR1420041010050500013M026A6', + 'FR14A0041010050500013M02606', + 'FR1420041010050500013M026069', + ], + }, + { + locale: 'GB', + valid: ['GB29NWBK60161331926819'], + invalid: [ + 'GB29NWBK60161331926811', + 'GB29NWBK6016133192681A', + 'GB29N9BK60161331926819', + 'GB29NWBK601613319268199', + ], + }, + { + locale: 'GE', + valid: ['GE29NB0000000101904917'], + invalid: [ + 'GE29NB0000000101904919', + 'GE29NB000000010190491A', + 'GE29N90000000101904917', + 'GE29NB00000001019049179', + ], + }, + { + locale: 'GI', + valid: ['GI75NWBK000000007099453'], + invalid: ['GI75NWBK000000007099459', 'GI75N9BK000000007099453', 'GI75NWBK0000000070994539'], + }, + { + locale: 'GL', + valid: ['GL8964710001000206'], + invalid: ['GL8964710001000209', 'GL896471000100020A', 'GL89647100010002069'], + }, + { + locale: 'GR', + valid: ['GR1601101250000000012300695'], + invalid: [ + 'GR1601101250000000012300699', + 'GR16A1101250000000012300695', + 'GR16011012500000000123006959', + ], + }, + { + locale: 'HU', + valid: ['HU42117730161111101800000000'], + invalid: [ + 'HU42117730161111101800000009', + 'HU4211773016111110180000000A', + 'HU421177301611111018000000009', + ], + }, + { + locale: 'HR', + valid: ['HR1210010051863000160'], + invalid: ['HR1210010051863000169', 'HR121001005186300016A', 'HR12100100518630001609'], + }, + { + locale: 'IE', + valid: ['IE29AIBK93115212345678'], + invalid: [ + 'IE29AIBK93115212345679', + 'IE29AEBK9311521234567A', + 'IE29A9BK93115212345678', + 'IE29AIBK931152123456789', + ], + }, + { + locale: 'IS', + valid: ['IS140159260076545510730339'], + invalid: [ + 'IS140159260076545510730331', + 'IS14015926007654551073033A', + 'IS1401592600765455107303399', + ], + }, + { + locale: 'IT', + valid: ['IT60X0542811101000000123456'], + invalid: [ + 'IT60X0542811101000000123459', + 'IT6090542811101000000123456', + 'IT60XA542811101000000123456', + 'IT60X05428111010000001234569', + ], + }, + { + locale: 'JO', + valid: ['JO94CBJO0010000000000131000302'], + invalid: [ + 'JO94CBJO0010000000000131000309', + 'JO94C9JO0010000000000131000302', + 'JO94CBJOA010000000000131000302', + 'JO94CBJO00100000000001310003029', + ], + }, + { + locale: 'KW', + valid: ['KW81CBKU0000000000001234560101'], + invalid: [ + 'KW81CBKU0000000000001234560109', + 'KW81CB9U0000000000001234560101', + 'KW81CBKU00000000000012345601019', ], + }, + { + locale: 'KZ', + valid: ['KZ86125KZT5004100100'], + invalid: ['KZ86125KZT5004100109', 'KZ86125K9T5004100100', 'KZ86125KZT50041001009'], + }, + { + locale: 'LB', + valid: ['LB62099900000001001901229114'], invalid: [ - '+30982345679', - '982345679', - '+380 98 234 5679', - '+380-98-234-5679', - '', - 'ASDFGJKLmZXJtZtesting123', - '123456', - '740123456', + 'LB62099900000001001901229119', + 'LB6209A900000001001901229114', + 'LB620999000000010019012291149', ], }, { - locale: 'da-DK', - valid: [ - '12345678', - '12 34 56 78', - '45 12345678', - '4512345678', - '45 12 34 56 78', - '+45 12 34 56 78', + locale: 'LI', + valid: ['LI21088100002324013AA'], + invalid: ['LI21088100002324013A9', 'LI21A88100002324013AA', 'LI21088100002324013AA9'], + }, + { + locale: 'LT', + valid: ['LT121000011101001000'], + invalid: ['LT121000011101001009', 'LT12100001110100100A', 'LT1210000111010010009'], + }, + { + locale: 'LV', + valid: ['LV80BANK0000435195001'], + invalid: ['LV80BANK0000435195009', 'LV80B9NK0000435195001', 'LV80BANK00004351950019'], + }, + { + locale: 'MC', + valid: ['MC5811222000010123456789030'], + invalid: [ + 'MC5811222000010123456789039', + 'MC581122200001012345678903A', + 'MC58A1222000010123456789030', + 'MC58112220000101234567890309', ], + }, + { + locale: 'MD', + valid: ['MD24AG000225100013104168'], invalid: [ - '', - '+45010203', - 'ASDFGJKLmZXJtZtesting123', - '123456', - '12 34 56', - '123 123 12', + 'MD24AG000225100013104169', + 'MD24A9000225100013104168', + 'MD24AG0002251000131041689', ], }, { - locale: 'sv-SE', - valid: [ - '+46701234567', - '46701234567', - '0721234567', - '073-1234567', - '0761-234567', - '079-123 45 67', + locale: 'ME', + valid: ['ME25505000012345678951'], + invalid: ['ME25505000012345678959', 'ME2550500001234567895A', 'ME255050000123456789519'], + }, + { + locale: 'MK', + valid: ['MK07250120000058984'], + invalid: ['MK07250120000058989', 'MK07A50120000058984', 'MK072501200000589849'], + }, + { + locale: 'MT', + valid: ['MT84MALT011000012345MTLCAST001S'], + invalid: [ + 'MT84MALT011000012345MTLCAST0019', + 'MT84M9LT011000012345MTLCAST001S', + 'MT84MALT0A1000012345MTLCAST001S', + 'MT84MALT011000012345MTLCAST001S9', ], + }, + { + locale: 'NL', + valid: ['NL91ABNA0417164300'], invalid: [ - '12345', - '+4670123456', - '+46301234567', - '+0731234567', - '0731234 56', - '+7312345678', - '', + 'NL91ABNA0417164309', + 'NL91AB9A0417164300', + 'NL91ABNA041716430A', + 'NL91ABNA04171643009', ], }, { - locale: 'fo-FO', - valid: [ - '123456', - '12 34 56', - '298 123456', - '298123456', - '298 12 34 56', - '+298 12 34 56', + locale: 'NO', + valid: ['NO9386011117947'], + invalid: ['NO9386011117949', 'NO938601111794A', 'NO93860111179479'], + }, + { + locale: 'PL', + valid: ['PL61109010140000071219812874'], + invalid: [ + 'PL61109010140000071219812879', + 'PL6110901014000007121981287A', + 'PL611090101400000712198128749', ], + }, + { + locale: 'PS', + valid: ['PS92PALS000000000400123456702'], invalid: [ - '', - '+4501020304', - 'ASDFGJKLmZXJtZtesting123', - '12345678', - '12 34 56 78', + 'PS92PALS000000000400123456709', + 'PS92P9LS000000000400123456702', + 'PS92PALS0000000004001234567029', ], }, { - locale: 'kl-GL', - valid: [ - '123456', - '12 34 56', - '299 123456', - '299123456', - '299 12 34 56', - '+299 12 34 56', + locale: 'PT', + valid: ['PT50000201231234567890154'], + invalid: [ + 'PT50000201231234567890159', + 'PT5000020123123456789015A', + 'PT500002012312345678901549', ], + }, + { + locale: 'QA', + valid: ['QA73BBME000000000004056677001'], invalid: [ - '', - '+4501020304', - 'ASDFGJKLmZXJtZtesting123', - '12345678', - '12 34 56 78', + 'QA73BBME000000000004056677009', + 'QA73B9ME000000000004056677001', + 'QA73BBME0000000000040566770019', ], }, { - locale: 'kk-KZ', - valid: [ - '+77254716212', - '77254716212', - '87254716212', - '7254716212', + locale: 'RO', + valid: ['RO49AAAA1B31007593840000'], + invalid: [ + 'RO49AAAA1B31007593840009', + 'RO49A9AA1B31007593840000', + 'RO49AAAA1B310075938400009', ], + }, + { + locale: 'SA', + valid: ['SA0380000000608010167519'], invalid: [ - '12345', - '', - 'ASDFGJKLmZXJtZtesting123', - '010-38238383', - '+9676338855', - '19676338855', - '6676338855', - '+99676338855', + 'SA0380000000608010167511', + 'SA03A0000000608010167519', + 'SA03800000006080101675199', ], }, { - locale: 'be-BY', - valid: [ - '+375241234567', - '+375251234567', - '+375291234567', - '+375331234567', - '+375441234567', - '375331234567', + locale: 'SE', + valid: ['SE4550000000058398257466'], + invalid: [ + 'SE4550000000058398257469', + 'SE455000000005839825746A', + 'SE45500000000583982574669', ], + }, + { + locale: 'SI', + valid: ['SI56263300012039086'], + invalid: ['SI56263300012039089', 'SI5626330001203908A', 'SI562633000120390869'], + }, + { + locale: 'SK', + valid: ['SK3112000000198742637541'], invalid: [ - '12345', - '', - 'ASDFGJKLmZXJtZtesting123', - '010-38238383', - '+9676338855', - '19676338855', - '6676338855', - '+99676338855', + 'SK3112000000198742637549', + 'SK311200000019874263754A', + 'SK31120000001987426375419', ], }, { - locale: 'th-TH', - valid: [ - '0912345678', - '+66912345678', - '66912345678', + locale: 'SM', + valid: ['SM86U0322509800000000270100'], + invalid: [ + 'SM86U0322509800000000270109', + 'SM8690322509800000000270100', + 'SM86UA322509800000000270100', + 'SM86U03225098000000002701009', ], + }, + { + locale: 'RS', + valid: ['RS35260005601001611379'], + invalid: ['RS35260005601001611371', 'RS3526000560100161137A', 'RS352600056010016113799'], + }, + { + locale: 'TN', + valid: ['TN5910006035183598478831'], invalid: [ - '99123456789', - '12345', - '67812345623', - '081234567891', + 'TN5910006035183598478839', + 'TN591000603518359847883A', + 'TN59100060351835984788319', ], }, { - locale: ['en-ZA', 'be-BY'], - valid: [ - '0821231234', - '+27821231234', - '27821231234', - '+375241234567', - '+375251234567', - '+375291234567', - '+375331234567', - '+375441234567', - '375331234567', + locale: 'TR', + valid: ['TR330006100519786457841326'], + invalid: [ + 'TR330006100519786457841329', + 'TR33A006100519786457841326', + 'TR3300061005197864578413269', ], + }, + { + locale: 'UA', + valid: ['UA213996220000026007233566001'], invalid: [ - '082123', - '08212312345', - '21821231234', - '+21821231234', - '+0821231234', - '12345', - '', - 'ASDFGJKLmZXJtZtesting123', - '010-38238383', - '+9676338855', - '19676338855', - '6676338855', - '+99676338855', + 'UA213996220000026007233566009', + 'UA21A996220000026007233566001', + 'UA2139962200000260072335660019', ], }, + { + locale: 'XK', + valid: ['XK051212012345678906'], + invalid: ['XK051212012345678909', 'XK05121201234567890A', 'XK0512120123456789069'], + }, ]; let allValid = []; @@ -5195,25 +4605,16 @@ describe('Validators', () => { // to be used later on for validating 'any' locale if (fixture.valid) allValid = allValid.concat(fixture.valid); - if (Array.isArray(fixture.locale)) { - test({ - validator: 'isMobilePhone', - valid: fixture.valid, - invalid: fixture.invalid, - args: [fixture.locale], - }); - } else { - test({ - validator: 'isMobilePhone', - valid: fixture.valid, - invalid: fixture.invalid, - args: [fixture.locale], - }); - } + test({ + validator: 'isIBAN', + valid: fixture.valid, + invalid: fixture.invalid, + args: [fixture.locale], + }); }); test({ - validator: 'isMobilePhone', + validator: 'isIBAN', valid: allValid, invalid: [ '', @@ -5225,33 +4626,32 @@ describe('Validators', () => { args: ['any'], }); - // strict mode + // falsey locale defaults to 'any' test({ - validator: 'isMobilePhone', - valid: [ - '+254728530234', - '+299 12 34 56', - ], + validator: 'isIBAN', + valid: allValid, invalid: [ - '254728530234', - '0728530234', - '+728530234', + '', + 'asdf', + '1', + 'ASDFGJKLmZXJtZtesting123', + 'Vml2YW11cyBmZXJtZtesting123', ], - args: ['any', { strictMode: true }], + args: [], }); + }); - // falsey locale defaults to 'any' + it('should error on invalid locale isIBAN', () => { test({ - validator: 'isMobilePhone', - valid: allValid, - invalid: [ + validator: 'isIBAN', + args: ['is-NOT'], + error: [ '', 'asdf', '1', 'ASDFGJKLmZXJtZtesting123', 'Vml2YW11cyBmZXJtZtesting123', ], - args: [], }); }); @@ -6174,20 +5574,8 @@ describe('Validators', () => { it('should validate booleans', () => { test({ validator: 'isBoolean', - valid: [ - 'true', - 'false', - '0', - '1', - ], - invalid: [ - '1.0', - '0.0', - 'true ', - 'False', - 'True', - 'yes', - ], + valid: ['true', 'false', '0', '1'], + invalid: ['1.0', '0.0', 'true ', 'False', 'True', 'yes'], }); }); @@ -6276,9 +5664,7 @@ describe('Validators', () => { it('should validate ISO 8601 dates, with strict = true (regression)', () => { test({ validator: 'isISO8601', - args: [ - { strict: true }, - ], + args: [{ strict: true }], valid: validISO8601, invalid: invalidISO8601, }); @@ -6345,30 +5731,8 @@ describe('Validators', () => { // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 test({ validator: 'isISO31661Alpha2', - valid: [ - 'FR', - 'fR', - 'GB', - 'PT', - 'CM', - 'JP', - 'PM', - 'ZW', - 'MM', - 'cc', - 'GG', - ], - invalid: [ - '', - 'FRA', - 'AA', - 'PI', - 'RP', - 'WV', - 'WL', - 'UK', - 'ZZ', - ], + valid: ['FR', 'fR', 'GB', 'PT', 'CM', 'JP', 'PM', 'ZW', 'MM', 'cc', 'GG'], + invalid: ['', 'FRA', 'AA', 'PI', 'RP', 'WV', 'WL', 'UK', 'ZZ'], }); }); @@ -6376,23 +5740,8 @@ describe('Validators', () => { // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 test({ validator: 'isISO31661Alpha3', - valid: [ - 'ABW', - 'HND', - 'KHM', - 'RWA', - ], - invalid: [ - '', - 'FR', - 'fR', - 'GB', - 'PT', - 'CM', - 'JP', - 'PM', - 'ZW', - ], + valid: ['ABW', 'HND', 'KHM', 'RWA'], + invalid: ['', 'FR', 'fR', 'GB', 'PT', 'CM', 'JP', 'PM', 'ZW'], }); }); @@ -6435,7 +5784,8 @@ describe('Validators', () => { 'data:,A%20brief%20invalid%20[note', 'file:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D', 'data:text/html;charset=,%3Ch1%3EHello!%3C%2Fh1%3E', - 'data:text/html;charset,%3Ch1%3EHello!%3C%2Fh1%3E', 'data:base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', + 'data:text/html;charset,%3Ch1%3EHello!%3C%2Fh1%3E', + 'data:base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', '', 'http://wikipedia.org', 'base64', @@ -6445,7 +5795,6 @@ describe('Validators', () => { /* eslint-enable max-len */ }); - it('should validate magnetURI', () => { /* eslint-disable max-len */ test({ @@ -6477,7 +5826,6 @@ describe('Validators', () => { /* eslint-enable max-len */ }); - it('should validate LatLong', () => { test({ validator: 'isLatLong', @@ -6543,43 +5891,19 @@ describe('Validators', () => { const fixtures = [ { locale: 'AU', - valid: [ - '4000', - '2620', - '3000', - '2017', - '0800', - ], + valid: ['4000', '2620', '3000', '2017', '0800'], }, { locale: 'CA', - valid: [ - 'L4T 0A5', - 'G1A-0A2', - 'A1A 1A1', - 'X0A-0H0', - 'V5K 0A1', - ], + valid: ['L4T 0A5', 'G1A-0A2', 'A1A 1A1', 'X0A-0H0', 'V5K 0A1'], }, { locale: 'JP', - valid: [ - '135-0000', - '874-8577', - '669-1161', - '470-0156', - '672-8031', - ], + valid: ['135-0000', '874-8577', '669-1161', '470-0156', '672-8031'], }, { locale: 'GR', - valid: [ - '022 93', - '29934', - '90293', - '299 42', - '94944', - ], + valid: ['022 93', '29934', '90293', '299 42', '94944'], }, { locale: 'GB', @@ -6601,116 +5925,51 @@ describe('Validators', () => { }, { locale: 'FR', - valid: [ - '75008', - '44 522', - '98025', - '38 499', - '39940', - ], + valid: ['75008', '44 522', '98025', '38 499', '39940'], }, { locale: 'ID', - valid: [ - '10210', - '40181', - '55161', - '60233', - ], + valid: ['10210', '40181', '55161', '60233'], }, { locale: 'BG', - valid: [ - '1000', - ], + valid: ['1000'], }, { locale: 'CZ', - valid: [ - '20134', - '392 90', - '39919', - '938 29', - '39949', - ], + valid: ['20134', '392 90', '39919', '938 29', '39949'], }, { locale: 'NL', - valid: [ - '1012 SZ', - '3432FE', - '1118 BH', - '3950IO', - '3997 GH', - ], + valid: ['1012 SZ', '3432FE', '1118 BH', '3950IO', '3997 GH'], }, { locale: 'PL', - valid: [ - '47-260', - '12-930', - '78-399', - '39-490', - '38-483', - ], + valid: ['47-260', '12-930', '78-399', '39-490', '38-483'], }, { locale: 'TW', - valid: [ - '360', - '90312', - '399', - '935', - '38842', - ], + valid: ['360', '90312', '399', '935', '38842'], }, { locale: 'LI', - valid: [ - '9485', - '9497', - '9491', - '9489', - '9496', - ], + valid: ['9485', '9497', '9491', '9489', '9496'], }, { locale: 'PT', - valid: [ - '4829-489', - '0294-348', - '8156-392', - ], + valid: ['4829-489', '0294-348', '8156-392'], }, { locale: 'SE', - valid: [ - '12994', - '284 39', - '39556', - '489 39', - '499 49', - ], + valid: ['12994', '284 39', '39556', '489 39', '499 49'], }, { locale: 'AD', - valid: [ - 'AD100', - 'AD200', - 'AD300', - 'AD400', - 'AD500', - 'AD600', - 'AD700', - ], + valid: ['AD100', 'AD200', 'AD300', 'AD400', 'AD500', 'AD600', 'AD700'], }, { locale: 'UA', - valid: [ - '65000', - '65080', - '01000', - ], + valid: ['65000', '65080', '01000'], }, { locale: 'BR', diff --git a/validator.js b/validator.js index f9fe7b4da..18e0b586d 100644 --- a/validator.js +++ b/validator.js @@ -131,7 +131,7 @@ function equals(str, comparison) { return str === comparison; } -function toString$1(input) { +function toString(input) { if (_typeof(input) === 'object' && input !== null) { if (typeof input.toString === 'function') { input = input.toString(); @@ -147,7 +147,7 @@ function toString$1(input) { function contains(str, elem) { assertString(str); - return str.indexOf(toString$1(elem)) >= 0; + return str.indexOf(toString(elem)) >= 0; } function matches(str, pattern, modifiers) { @@ -1061,7 +1061,7 @@ function isIn(str, options) { // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes // istanbul ignore else if ({}.hasOwnProperty.call(options, i)) { - array[i] = toString$1(options[i]); + array[i] = toString(options[i]); } } @@ -2019,6 +2019,122 @@ function normalizeEmail(email, options) { return parts.join('@'); } +/* eslint-disable max-len */ + +var iban = { + AD: /^(AD[0-9]{2})\d{8}[0-9A-Z]{12}$/, + AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/, + AT: /^(AT[0-9]{2})\d{16}$/, + BA: /^(BA[0-9]{2})\d{16}$/, + BE: /^(BE[0-9]{2})\d{12}$/, + BG: /^(BG[0-9]{2})[A-Z]{4}\d{4}[A-Z0-9]{10}$/, + BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/, + BR: /^(BR[0-9]{2})\d{23}[A-Z][A-Z0-9]$/, + CH: /^(CH[0-9]{2})\d{17}$/, + CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/, + CZ: /^(CZ[0-9]{2})\d{20}$/, + DE: /^(DE[0-9]{2})\d{18}$/, + DK: /^(DK[0-9]{2})\d{14}$/, + EE: /^(EE[0-9]{2})\d{16}$/, + ES: /^(ES[0-9]{2})\d{20}$/, + FO: /^(FO[0-9]{2})\d{14}$/, + FI: /^(FI[0-9]{2})\d{14}$/, + FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/, + GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/, + GE: /^(GE[0-9]{2})[A-Z]{2}\d{16}$/, + GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/, + GL: /^(GL[0-9]{2})\d{14}$/, + GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/, + HR: /^(HR[0-9]{2})\d{17}$/, + HU: /^(HU[0-9]{2})\d{24}$/, + IE: /^(IE[0-9]{2})[A-Z]{4}\d{14}$/, + IS: /^(IS[0-9]{2})\d{22}$/, + IT: /^(IT[0-9]{2})[A-Z]\d{10}[A-Z0-9]{12}$/, + JO: /^(JO[0-9]{2})[A-Z]{4}\d{4}[A-Z0-9]{18}$/, + KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/, + KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/, + LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/, + LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/, + LT: /^(LT[0-9]{2})\d{16}$/, + LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/, + LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/, + MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/, + MD: /^(MD[0-9]{2})[A-Z]{2}[A-Z0-9]{18}$/, + ME: /^(ME[0-9]{2})\d{18}$/, + MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{12}$/, + MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/, + NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/, + NO: /^(NO[0-9]{2})\d{11}$/, + PL: /^(PL[0-9]{2})\d{24}$/, + PS: /^(PS[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/, + PT: /^(PT[0-9]{2})\d{21}$/, + QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/, + RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/, + SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/, + SE: /^(SE[0-9]{2})\d{20}$/, + SI: /^(SI[0-9]{2})\d{15}$/, + SK: /^(SK[0-9]{2})\d{20}$/, + SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/, + RS: /^(RS[0-9]{2})\d{18}$/, + TN: /^(TN[0-9]{2})\d{20}$/, + TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/, + UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/, + XK: /^(XK[0-9]{2})\d{16}$/ +}; +/* eslint-enable max-len */ + +/** + * @function IbanCalcul - calculate if the IBAN corresponds to the reglementation: converting + * it into an integer and performing a basic mod-97 operation. If the IBAN is valid, the remainder + * equals 1. + * 1- Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid + * 2- Move the four initial characters to the end of the string + * 3- Replace each letter in the string with two digits, thereby expanding the string, + * where A = 10..., Z = 35 + * 4- Interpret the string as a decimal integer and compute the remainder of that number on + * division by 97 + * @param {e} - recieves the IBAN tested + * @warns IBAN's length differs from country to another, the maximum length is 34 characters so + * calculating its modulus 97 is not possible for all machines.To solve this, the function calculate + * the modulus of the first 9 digit by 97 and add the result to the beginning of the remain IBAN + * number. The process is repeated untill the result's length is less than 10 + */ + +var IbanCalcul = function IbanCalcul(e) { + var countryCode = e.slice(0, 4); + var result = e.slice(4, e.length) + countryCode; + + for (var counter = 1; counter <= Math.ceil(e.length / 10) + 1; counter++) { + var remainder = result.slice(0, 10).replace(/[A-Z]/g, function (element) { + return element.charCodeAt() - 55; + }) % 97; + result = remainder + result.slice(10); + } + + if (result === '1') return true; + return false; +}; + +function isIBAN(str, locale) { + assertString(str); + str = str.toUpperCase(); + + if (locale in iban) { + return iban[locale].test(str) && IbanCalcul(str); + } else if (!locale || locale === 'any') { + locale = str.slice(0, 2); + + if (locale in iban) { + return iban[locale].test(str) && IbanCalcul(str); + } + + return false; + } + + throw new Error("Invalid locale '".concat(locale, "'")); +} +var locales$5 = Object.keys(iban); + var version = '11.1.0'; var validator = { version: version, @@ -2100,7 +2216,9 @@ var validator = { blacklist: blacklist$1, isWhitelisted: isWhitelisted, normalizeEmail: normalizeEmail, - toString: toString + toString: toString, + isIBAN: isIBAN, + isIBANLocales: locales$5 }; return validator; diff --git a/validator.min.js b/validator.min.js index 46acfae86..52a18feb3 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,4 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.validator=e()}(this,function(){"use strict";function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function g(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,l=t[Symbol.iterator]();!(n=(a=l.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==l.return||l.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function $(t){var e;if(!("string"==typeof t||t instanceof String))throw e=null===t?"null":"object"===(e=a(t))&&t.constructor&&t.constructor.hasOwnProperty("name")?t.constructor.name:"a ".concat(e),new TypeError("Expected string but received ".concat(e,"."))}function o(t){return $(t),t=Date.parse(t),isNaN(t)?null:new Date(t)}function r(t){return $(t),parseFloat(t)}function i(t){return"object"===a(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function m(t,e){var r=0i)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(r.shift(),r.shift(),n=!0):"::"===t.substr(t.length-2)&&(r.pop(),r.pop(),n=!0);for(var a=0;a$/i,E=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,M=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,N=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,C=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;var d={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},f=/^\[([^\]]+)\](?::([0-9]+))?$/;function p(t,e){for(var r=0;r=e.min,o=!e.hasOwnProperty("max")||t<=e.max,i=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&o&&i&&a}var V=/^[\x00-\x7F]+$/;var j=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var J=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var q=/[^\x00-\x7F]/;var Q=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function X(t,e){return t.some(function(t){return e===t})}var tt=Object.keys(T);var et={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},rt=["","-","+"];var nt=/^[0-9A-F]+$/i;function ot(t){return $(t),nt.test(t)}var it=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;var at=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var lt=/^[a-f0-9]{32}$/;var st={md5:32,md4:32,sha1:40,sha256:64,sha384:96,sha512:128,ripemd128:32,ripemd160:40,tiger128:32,tiger160:40,tiger192:48,crc32:8,crc32b:8};var ut=/^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/;var ct={ignore_whitespace:!1};var dt={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};var ft=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;var pt={ES:function(t){$(t);var e={X:0,Y:1,Z:2},r=t.trim().toUpperCase();if(!/^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/.test(r))return!1;var n=r.slice(0,-1).replace(/[X,Y,Z]/g,function(t){return e[t]});return r.endsWith(["T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E"][n%23])},"he-IL":function(t){var e=t.trim();if(!/^\d{9}$/.test(e))return!1;for(var r,n=e,o=0,i=0;i]/.test(r)){if(!e)return!1;if(!(r.split('"').length===r.split('\\"').length))return!1}return!0}(n))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,n,o,i,a,l,s,u;if(e=m(e,d),1<(s=(t=(s=(t=(s=t.split("#")).shift()).split("?")).shift()).split("://")).length){if(r=s.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(r))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;s[0]=t.substr(2)}}if(""===(t=s.join("://")))return!1;if(""===(t=(s=t.split("/")).shift())&&!e.require_host)return!0;if(1<(s=t.split("@")).length){if(e.disallow_auth)return!1;if(0<=(n=s.shift()).indexOf(":")&&2=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)},isFloatLocales:tt,isDecimal:function(t,e){if($(t),(e=m(e,et)).locale in T)return!X(rt,t.replace(/ /g,""))&&function(t){return new RegExp("^[-+]?([0-9]+)?(\\".concat(T[t.locale],"[0-9]{").concat(t.decimal_digits,"})").concat(t.force_decimal?"":"?","$"))}(e).test(t);throw new Error("Invalid locale '".concat(e.locale,"'"))},isHexadecimal:ot,isDivisibleBy:function(t,e){return $(t),r(t)%parseInt(e,10)==0},isHexColor:function(t){return $(t),it.test(t)},isISRC:function(t){return $(t),at.test(t)},isMD5:function(t){return $(t),lt.test(t)},isHash:function(t,e){return $(t),new RegExp("^[a-fA-F0-9]{".concat(st[e],"}$")).test(t)},isJWT:function(t){return $(t),ut.test(t)},isJSON:function(t){$(t);try{var e=JSON.parse(t);return!!e&&"object"===a(e)}catch(t){}return!1},isEmpty:function(t,e){return $(t),0===((e=m(e,ct)).ignore_whitespace?t.trim().length:t.length)},isLength:function(t,e){var r,n;$(t),n="object"===a(e)?(r=e.min||0,e.max):(r=e||0,arguments[2]);var o=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-o.length;return r<=i&&(void 0===n||i<=n)},isByteLength:v,isUUID:function(t){var e=1/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return $(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return $(t),Jt(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return $(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Jt,isWhitelisted:function(t,e){$(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=m(e,qt);var r=t.split("@"),n=r.pop(),o=[r.join("@"),n];if(o[1]=o[1].toLowerCase(),"gmail.com"===o[1]||"googlemail.com"===o[1]){if(e.gmail_remove_subaddress&&(o[0]=o[0].split("+")[0]),e.gmail_remove_dots&&(o[0]=o[0].replace(/\.+/g,re)),!o[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(o[0]=o[0].toLowerCase()),o[1]=e.gmail_convert_googlemaildotcom?"gmail.com":o[1]}else if(0<=Qt.indexOf(o[1])){if(e.icloud_remove_subaddress&&(o[0]=o[0].split("+")[0]),!o[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(o[0]=o[0].toLowerCase())}else if(0<=Xt.indexOf(o[1])){if(e.outlookdotcom_remove_subaddress&&(o[0]=o[0].split("+")[0]),!o[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(o[0]=o[0].toLowerCase())}else if(0<=te.indexOf(o[1])){if(e.yahoo_remove_subaddress){var i=o[0].split("-");o[0]=1i)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(r.shift(),r.shift(),n=!0):"::"===t.substr(t.length-2)&&(r.pop(),r.pop(),n=!0);for(var a=0;a$/i,E=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,R=/^[a-z\d]+$/,L=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,M=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,I=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;var d={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},f=/^\[([^\]]+)\](?::([0-9]+))?$/;function A(t,e){for(var r=0;r=e.min,o=!e.hasOwnProperty("max")||t<=e.max,i=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&o&&i&&a}var V=/^[\x00-\x7F]+$/;var j=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var J=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var q=/[^\x00-\x7F]/;var Q=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function X(t,e){return t.some(function(t){return e===t})}var tt=Object.keys(x);var et={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},rt=["","-","+"];var nt=/^[0-9A-F]+$/i;function ot(t){return g(t),nt.test(t)}var it=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;var at=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var lt=/^[a-f0-9]{32}$/;var st={md5:32,md4:32,sha1:40,sha256:64,sha384:96,sha512:128,ripemd128:32,ripemd160:40,tiger128:32,tiger160:40,tiger192:48,crc32:8,crc32b:8};var ut=/^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/;var ct={ignore_whitespace:!1};var dt={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};var ft=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;var At={ES:function(t){g(t);var e={X:0,Y:1,Z:2},r=t.trim().toUpperCase();if(!/^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/.test(r))return!1;var n=r.slice(0,-1).replace(/[X,Y,Z]/g,function(t){return e[t]});return r.endsWith(["T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E"][n%23])},"he-IL":function(t){var e=t.trim();if(!/^\d{9}$/.test(e))return!1;for(var r,n=e,o=0,i=0;i]/.test(r)){if(!e)return!1;if(!(r.split('"').length===r.split('\\"').length))return!1}return!0}(n))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,n,o,i,a,l,s,u;if(e=m(e,d),1<(s=(t=(s=(t=(s=t.split("#")).shift()).split("?")).shift()).split("://")).length){if(r=s.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(r))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;s[0]=t.substr(2)}}if(""===(t=s.join("://")))return!1;if(""===(t=(s=t.split("/")).shift())&&!e.require_host)return!0;if(1<(s=t.split("@")).length){if(e.disallow_auth)return!1;if(0<=(n=s.shift()).indexOf(":")&&2=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)},isFloatLocales:tt,isDecimal:function(t,e){if(g(t),(e=m(e,et)).locale in x)return!X(rt,t.replace(/ /g,""))&&function(t){return new RegExp("^[-+]?([0-9]+)?(\\".concat(x[t.locale],"[0-9]{").concat(t.decimal_digits,"})").concat(t.force_decimal?"":"?","$"))}(e).test(t);throw new Error("Invalid locale '".concat(e.locale,"'"))},isHexadecimal:ot,isDivisibleBy:function(t,e){return g(t),r(t)%parseInt(e,10)==0},isHexColor:function(t){return g(t),it.test(t)},isISRC:function(t){return g(t),at.test(t)},isMD5:function(t){return g(t),lt.test(t)},isHash:function(t,e){return g(t),new RegExp("^[a-fA-F0-9]{".concat(st[e],"}$")).test(t)},isJWT:function(t){return g(t),ut.test(t)},isJSON:function(t){g(t);try{var e=JSON.parse(t);return!!e&&"object"===a(e)}catch(t){}return!1},isEmpty:function(t,e){return g(t),0===((e=m(e,ct)).ignore_whitespace?t.trim().length:t.length)},isLength:function(t,e){var r,n;g(t),n="object"===a(e)?(r=e.min||0,e.max):(r=e||0,arguments[2]);var o=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-o.length;return r<=i&&(void 0===n||i<=n)},isByteLength:v,isUUID:function(t){var e=1/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return g(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return g(t),Jt(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return g(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Jt,isWhitelisted:function(t,e){g(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=m(e,qt);var r=t.split("@"),n=r.pop(),o=[r.join("@"),n];if(o[1]=o[1].toLowerCase(),"gmail.com"===o[1]||"googlemail.com"===o[1]){if(e.gmail_remove_subaddress&&(o[0]=o[0].split("+")[0]),e.gmail_remove_dots&&(o[0]=o[0].replace(/\.+/g,re)),!o[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(o[0]=o[0].toLowerCase()),o[1]=e.gmail_convert_googlemaildotcom?"gmail.com":o[1]}else if(0<=Qt.indexOf(o[1])){if(e.icloud_remove_subaddress&&(o[0]=o[0].split("+")[0]),!o[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(o[0]=o[0].toLowerCase())}else if(0<=Xt.indexOf(o[1])){if(e.outlookdotcom_remove_subaddress&&(o[0]=o[0].split("+")[0]),!o[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(o[0]=o[0].toLowerCase())}else if(0<=te.indexOf(o[1])){if(e.yahoo_remove_subaddress){var i=o[0].split("-");o[0]=1