From 8772de2d7bcc7ca55cbe72998db9f8e22618b06c Mon Sep 17 00:00:00 2001 From: Nizar Date: Tue, 21 May 2019 13:31:14 +0100 Subject: [PATCH 1/2] feat(isIBAN): added isIBAN validattion check if the string is IBAN number, (locale is one of ['AD','AT','BH','BE','BA','BG','CY','CZ','DE','DK','EE','FO','FI','FR','GB','GE','GI','GL','GR','HU','HR','IE','IS','IT',TN] OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match with the first two letters of the IBAN which coincide with the country Alpha-2 code name). --- README.md | 177 ++- index.js | 6 +- lib/isIBAN.js | 128 ++ lib/isMobilePhone.js | 3 +- lib/isPostalCode.js | 1 + src/index.js | 4 + src/lib/isIBAN.js | 109 ++ test/validators.js | 2896 +++++++++++++++--------------------------- validator.js | 326 ++--- validator.min.js | 2 +- 10 files changed, 1495 insertions(+), 2157 deletions(-) create mode 100644 lib/isIBAN.js create mode 100644 src/lib/isIBAN.js diff --git a/README.md b/README.md index 7e1bfdeff..cff329b21 100644 --- a/README.md +++ b/README.md @@ -24,21 +24,21 @@ Install the library with `npm install validator` #### No ES6 ```javascript -var validator = require('validator'); +var validator = require("validator"); -validator.isEmail('foo@bar.com'); //=> true +validator.isEmail("foo@bar.com"); //=> true ``` #### ES6 ```javascript -import validator from 'validator'; +import validator from "validator"; ``` Or, import only a subset of the library: ```javascript -import isEmail from 'validator/lib/isEmail'; +import isEmail from "validator/lib/isEmail"; ``` ### Client-side usage @@ -48,7 +48,7 @@ The library can be loaded either as a standalone script, or through an [AMD][amd ```html ``` @@ -72,87 +72,88 @@ Thank you to the people who have already contributed: Here is a list of the validators currently available. -Validator | Description ---------------------------------------- | -------------------------------------- -***contains(str, seed)*** | check if the string contains the seed. -**equals(str, comparison)** | check if the string matches the comparison. -**isAfter(str [, date])** | check if the string is a date that's after the specified date (defaults to now). -**isAlpha(str [, locale])** | check if the string contains only letters (a-zA-Z).

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. -**isAlphanumeric(str [, locale])** | check if the string contains only letters and numbers.

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. -**isAscii(str)** | check if the string contains ASCII chars only. -**isBase64(str)** | check if a string is base64 encoded. -**isBefore(str [, date])** | check if the string is a date that's before the specified date. -**isBoolean(str)** | check if a string is a boolean. -**isByteLength(str [, options])** | check if the string's length (in UTF-8 bytes) falls in a range.

`options` is an object which defaults to `{min:0, max: undefined}`. -**isCreditCard(str)** | check if the string is a credit card. -**isCurrency(str [, options])** | check if the string is a valid currency amount.

`options` is an object which defaults to `{symbol: '$', require_symbol: false, allow_space_after_symbol: false, symbol_after_digits: false, allow_negatives: true, parens_for_negatives: false, negative_sign_before_digits: false, negative_sign_after_digits: false, allow_negative_sign_placeholder: false, thousands_separator: ',', decimal_separator: '.', allow_decimal: true, require_decimal: false, digits_after_decimal: [2], allow_space_after_digits: false}`.
**Note:** The array `digits_after_decimal` is filled with the exact number of digits allowed not a range, for example a range 1 to 3 will be given as [1, 2, 3]. -**isDataURI(str)** | check if the string is a [data uri format](https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs). -**isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). -**isDecimal(str [, options])** | check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.

`options` is an object which defaults to `{force_decimal: false, decimal_digits: '1,', locale: 'en-US'}`

`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'ku-IQ', nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`.
**Note:** `decimal_digits` is given as a range like '1,3', a specific value like '3' or min like '1,'. -**isDivisibleBy(str, number)** | check if the string is a number that's divisible by another. -**isEmail(str [, options])** | check if the string is an email.

`options` is an object which defaults to `{ allow_display_name: false, require_display_name: false, allow_utf8_local_part: true, require_tld: true, allow_ip_domain: false, domain_specific_validation: false }`. If `allow_display_name` is set to true, the validator will also match `Display Name `. If `require_display_name` is set to true, the validator will reject strings without the format `Display Name `. If `allow_utf8_local_part` is set to false, the validator will not allow any non-English UTF8 character in email address' local part. If `require_tld` is set to false, e-mail addresses without having TLD in their domain will also be matched. If `allow_ip_domain` is set to true, the validator will allow IP addresses in the host part. If `domain_specific_validation` is true, some additional validation will be enabled, e.g. disallowing certain syntactically valid email addresses that are rejected by GMail. -**isEmpty(str [, options])** | check if the string has a length of zero.

`options` is an object which defaults to `{ ignore_whitespace:false }`. -**isFQDN(str [, options])** | check if the string is a fully qualified domain name (e.g. domain.com).

`options` is an object which defaults to `{ require_tld: true, allow_underscores: false, allow_trailing_dot: false }`. -**isFloat(str [, options])** | check if the string is a float.

`options` is an object which can contain the keys `min`, `max`, `gt`, and/or `lt` to validate the float is within boundaries (e.g. `{ min: 7.22, max: 9.55 }`) it also has `locale` as an option.

`min` and `max` are equivalent to 'greater or equal' and 'less or equal', respectively while `gt` and `lt` are their strict counterparts.

`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. Locale list is `validator.isFloatLocales`. -**isFullWidth(str)** | check if the string contains any full-width chars. -**isHalfWidth(str)** | check if the string contains any half-width chars. -**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. -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES']` 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). -**isISBN(str [, version])** | check if the string is an ISBN (version 10 or 13). -**isISSN(str [, options])** | check if the string is an [ISSN](https://en.wikipedia.org/wiki/International_Standard_Serial_Number).

`options` is an object which defaults to `{ case_sensitive: false, require_hyphen: false }`. If `case_sensitive` is true, ISSNs with a lowercase `'x'` as the check digit are rejected. -**isISIN(str)** | check if the string is an [ISIN][ISIN] (stock/security identifier). -**isISO8601(str)** | check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date; for additional checks for valid dates, e.g. invalidates dates like `2009-02-29`, pass `options` object as a second parameter with `options.strict = true`. -**isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. -**isISO31661Alpha2(str)** | check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code. -**isISO31661Alpha3(str)** | check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code. -**isISRC(str)** | check if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code). -**isIn(str, values)** | check if the string is in a array of allowed values. -**isInt(str [, options])** | check if the string is an integer.

`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4). -**isJSON(str)** | check if the string is valid JSON (note: uses JSON.parse). -**isJWT(str)** | check if the string is valid JWT token. -**isLatLong(str)**                     | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`. -**isLength(str [, options])** | check if the string's length falls in a range.

`options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs. -**isLowercase(str)** | check if the string is lowercase. -**isMACAddress(str)** | check if the string is a MAC address.

`options` is an object which defaults to `{no_colons: false}`. If `no_colons` is true, the validator will allow MAC addresses without the colons. -**isMD5(str)** | check if the string is a MD5 hash. -**isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format -**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['ar-AE', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GH', 'en-HK', 'en-IE', 'en-IN', 'en-KE', 'en-MU', en-NG', 'en-NZ', 'en-RW', 'en-SG', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-PK', 'es-ES', 'es-MX', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'pt-BR', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. -**isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid]. -**isMultibyte(str)** | check if the string contains one or more multibyte chars. -**isNumeric(str [, options])** | check if the string contains only numbers.

`options` is an object which defaults to `{no_symbols: false}`. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`). -**isPort(str)** | check if the string is a valid port number. -**isPostalCode(str, locale)** | check if the string is a postal code,

(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. Locale list is `validator.isPostalCodeLocales`.). -**isSurrogatePair(str)** | check if the string contains any surrogate pairs chars. -**isURL(str [, options])** | check if the string is an URL.

`options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_host: true, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, disallow_auth: false }`. -**isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). -**isUppercase(str)** | check if the string is uppercase. -**isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. -**isWhitelisted(str, chars)** | checks characters if they appear in the whitelist. -**matches(str, pattern [, modifiers])** | check if string matches the pattern.

Either `matches('foo', /foo/i)` or `matches('foo', 'foo', 'i')`. +| Validator | Description | +| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **_contains(str, seed)_** | check if the string contains the seed. | +| **equals(str, comparison)** | check if the string matches the comparison. | +| **isAfter(str [, date])** | check if the string is a date that's after the specified date (defaults to now). | +| **isAlpha(str [, locale])** | check if the string contains only letters (a-zA-Z).

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. | +| **isAlphanumeric(str [, locale])** | check if the string contains only letters and numbers.

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. | +| **isAscii(str)** | check if the string contains ASCII chars only. | +| **isBase64(str)** | check if a string is base64 encoded. | +| **isBefore(str [, date])** | check if the string is a date that's before the specified date. | +| **isBoolean(str)** | check if a string is a boolean. | +| **isByteLength(str [, options])** | check if the string's length (in UTF-8 bytes) falls in a range.

`options` is an object which defaults to `{min:0, max: undefined}`. | +| **isCreditCard(str)** | check if the string is a credit card. | +| **isCurrency(str [, options])** | check if the string is a valid currency amount.

`options` is an object which defaults to `{symbol: '$', require_symbol: false, allow_space_after_symbol: false, symbol_after_digits: false, allow_negatives: true, parens_for_negatives: false, negative_sign_before_digits: false, negative_sign_after_digits: false, allow_negative_sign_placeholder: false, thousands_separator: ',', decimal_separator: '.', allow_decimal: true, require_decimal: false, digits_after_decimal: [2], allow_space_after_digits: false}`.
**Note:** The array `digits_after_decimal` is filled with the exact number of digits allowed not a range, for example a range 1 to 3 will be given as [1, 2, 3]. | +| **isDataURI(str)** | check if the string is a [data uri format](https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs). | +| **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). | +| **isDecimal(str [, options])** | check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.

`options` is an object which defaults to `{force_decimal: false, decimal_digits: '1,', locale: 'en-US'}`

`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'ku-IQ', nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`.
**Note:** `decimal_digits` is given as a range like '1,3', a specific value like '3' or min like '1,'. | +| **isDivisibleBy(str, number)** | check if the string is a number that's divisible by another. | +| **isEmail(str [, options])** | check if the string is an email.

`options` is an object which defaults to `{ allow_display_name: false, require_display_name: false, allow_utf8_local_part: true, require_tld: true, allow_ip_domain: false, domain_specific_validation: false }`. If `allow_display_name` is set to true, the validator will also match `Display Name `. If `require_display_name` is set to true, the validator will reject strings without the format `Display Name `. If `allow_utf8_local_part` is set to false, the validator will not allow any non-English UTF8 character in email address' local part. If `require_tld` is set to false, e-mail addresses without having TLD in their domain will also be matched. If `allow_ip_domain` is set to true, the validator will allow IP addresses in the host part. If `domain_specific_validation` is true, some additional validation will be enabled, e.g. disallowing certain syntactically valid email addresses that are rejected by GMail. | +| **isEmpty(str [, options])** | check if the string has a length of zero.

`options` is an object which defaults to `{ ignore_whitespace:false }`. | +| **isFQDN(str [, options])** | check if the string is a fully qualified domain name (e.g. domain.com).

`options` is an object which defaults to `{ require_tld: true, allow_underscores: false, allow_trailing_dot: false }`. | +| **isFloat(str [, options])** | check if the string is a float.

`options` is an object which can contain the keys `min`, `max`, `gt`, and/or `lt` to validate the float is within boundaries (e.g. `{ min: 7.22, max: 9.55 }`) it also has `locale` as an option.

`min` and `max` are equivalent to 'greater or equal' and 'less or equal', respectively while `gt` and `lt` are their strict counterparts.

`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. Locale list is `validator.isFloatLocales`. | +| **isFullWidth(str)** | check if the string contains any full-width chars. | +| **isHalfWidth(str)** | check if the string contains any half-width chars. | +| **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. | +| **isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES']` 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). | +| **isISBN(str [, version])** | check if the string is an ISBN (version 10 or 13). | +| **isISSN(str [, options])** | check if the string is an [ISSN](https://en.wikipedia.org/wiki/International_Standard_Serial_Number).

`options` is an object which defaults to `{ case_sensitive: false, require_hyphen: false }`. If `case_sensitive` is true, ISSNs with a lowercase `'x'` as the check digit are rejected. | +| **isISIN(str)** | check if the string is an [ISIN][isin] (stock/security identifier). | +| **isISO8601(str)** | check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date; for additional checks for valid dates, e.g. invalidates dates like `2009-02-29`, pass `options` object as a second parameter with `options.strict = true`. | +| **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. | +| **isISO31661Alpha2(str)** | check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code. | +| **isISO31661Alpha3(str)** | check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code. | +| **isISRC(str)** | check if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code). | +| **isIn(str, values)** | check if the string is in a array of allowed values. | +| **isInt(str [, options])** | check if the string is an integer.

`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4). | +| **isJSON(str)** | check if the string is valid JSON (note: uses JSON.parse). | +| **isJWT(str)** | check if the string is valid JWT token. | +| **isLatLong(str)**                     | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`. | +| **isLength(str [, options])** | check if the string's length falls in a range.

`options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs. | +| **isLowercase(str)** | check if the string is lowercase. | +| **isMACAddress(str)** | check if the string is a MAC address.

`options` is an object which defaults to `{no_colons: false}`. If `no_colons` is true, the validator will allow MAC addresses without the colons. | +| **isMD5(str)** | check if the string is a MD5 hash. | +| **isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format | +| **isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['ar-AE', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GH', 'en-HK', 'en-IE', 'en-IN', 'en-KE', 'en-MU', en-NG', 'en-NZ', 'en-RW', 'en-SG', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-PK', 'es-ES', 'es-MX', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'pt-BR', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. | +| **isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid]. | +| **isMultibyte(str)** | check if the string contains one or more multibyte chars. | +| **isNumeric(str [, options])** | check if the string contains only numbers.

`options` is an object which defaults to `{no_symbols: false}`. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`). | +| **isPort(str)** | check if the string is a valid port number. | +| **isPostalCode(str, locale)** | check if the string is a postal code,

(locale is one of `[ 'AD', 'AT', 'BE', 'BG', 'BH', 'BR', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FO', 'FI', 'FR', 'GB', 'GE', 'GI', 'GL', 'GR', 'HR', 'HU', 'IE', 'IS', 'IT', 'JO', 'KW', 'KZ', 'LB', 'LI', 'LT', 'LU', 'LV', 'MC', 'MD', 'ME', 'MK', 'MT', 'NL', 'NO', 'PL', 'PS', 'PT', 'QA', 'RO', 'SA', 'SE', 'SI', 'SK', 'SM', 'RS', 'TN', 'TR', 'UA', 'XK' ]` OR 'any'. If 'any' is used, function will check if any of the locals match. Locale list is `validator.isPostalCodeLocales`.). | +| **isSurrogatePair(str)** | check if the string contains any surrogate pairs chars. | +| **isURL(str [, options])** | check if the string is an URL.

`options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_host: true, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, disallow_auth: false }`. | +| **isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). | +| **isUppercase(str)** | check if the string is uppercase. | +| **isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. | +| **isWhitelisted(str, chars)** | checks characters if they appear in the whitelist. | +| **matches(str, pattern [, modifiers])** | check if string matches the pattern.

Either `matches('foo', /foo/i)` or `matches('foo', 'foo', 'i')`. | +| **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`.). | ## Sanitizers Here is a list of the sanitizers currently available. -Sanitizer | Description --------------------------------------- | ------------------------------- -**blacklist(input, chars)** | remove characters that appear in the blacklist. The characters are used in a RegExp and so you will need to escape some chars, e.g. `blacklist(input, '\\[\\]')`. -**escape(input)** | replace `<`, `>`, `&`, `'`, `"` and `/` with HTML entities. -**unescape(input)** | replaces HTML encoded entities with `<`, `>`, `&`, `'`, `"` and `/`. -**ltrim(input [, chars])** | trim characters from the left-side of the input. -**normalizeEmail(email [, options])** | canonicalizes an email address. (This doesn't validate that the input is an email, if you want to validate the email use isEmail beforehand)

`options` is an object with the following keys and default values:
  • *all_lowercase: true* - Transforms the local part (before the @ symbol) of all email addresses to lowercase. Please note that this may violate RFC 5321, which gives providers the possibility to treat the local part of email addresses in a case sensitive way (although in practice most - yet not all - providers don't). The domain part of the email address is always lowercased, as it's case insensitive per RFC 1035.
  • *gmail_lowercase: true* - GMail addresses are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, GMail addresses are lowercased regardless of the value of this setting.
  • *gmail_remove_dots: true*: Removes dots from the local part of the email address, as GMail ignores them (e.g. "john.doe" and "johndoe" are considered equal).
  • *gmail_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@gmail.com" becomes "foo@gmail.com").
  • *gmail_convert_googlemaildotcom: true*: Converts addresses with domain @googlemail.com to @gmail.com, as they're equivalent.
  • *outlookdotcom_lowercase: true* - Outlook.com addresses (including Windows Live and Hotmail) are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, Outlook.com addresses are lowercased regardless of the value of this setting.
  • *outlookdotcom_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@outlook.com" becomes "foo@outlook.com").
  • *yahoo_lowercase: true* - Yahoo Mail addresses are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, Yahoo Mail addresses are lowercased regardless of the value of this setting.
  • *yahoo_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "-" sign (e.g. "foo-bar@yahoo.com" becomes "foo@yahoo.com").
  • *icloud_lowercase: true* - iCloud addresses (including MobileMe) are known to be case-insensitive, so this switch allows lowercasing them even when *all_lowercase* is set to false. Please note that when *all_lowercase* is true, iCloud addresses are lowercased regardless of the value of this setting.
  • *icloud_remove_subaddress: true*: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@icloud.com" becomes "foo@icloud.com").
-**rtrim(input [, chars])** | trim characters from the right-side of the input. -**stripLow(input [, keep_new_lines])** | remove characters with a numerical value < 32 and 127, mostly control characters. If `keep_new_lines` is `true`, newline characters are preserved (`\n` and `\r`, hex `0xA` and `0xD`). Unicode-safe in JavaScript. -**toBoolean(input [, strict])** | convert the input string to a boolean. Everything except for `'0'`, `'false'` and `''` returns `true`. In strict mode only `'1'` and `'true'` return `true`. -**toDate(input)** | convert the input string to a date, or `null` if the input is not a date. -**toFloat(input)** | convert the input string to a float, or `NaN` if the input is not a float. -**toInt(input [, radix])** | convert the input string to an integer, or `NaN` if the input is not an integer. -**trim(input [, chars])** | trim characters (whitespace by default) from both sides of the input. -**whitelist(input, chars)** | remove characters that do not appear in the whitelist. The characters are used in a RegExp and so you will need to escape some chars, e.g. `whitelist(input, '\\[\\]')`. +| Sanitizer | Description | +| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| **blacklist(input, chars)** | remove characters that appear in the blacklist. The characters are used in a RegExp and so you will need to escape some chars, e.g. `blacklist(input, '\\[\\]')`. | +| **escape(input)** | replace `<`, `>`, `&`, `'`, `"` and `/` with HTML entities. | +| **unescape(input)** | replaces HTML encoded entities with `<`, `>`, `&`, `'`, `"` and `/`. | +| **ltrim(input [, chars])** | trim characters from the left-side of the input. | +| **normalizeEmail(email [, options])** | canonicalizes an email address. (This doesn't validate that the input is an email, if you want to validate the email use isEmail beforehand)

`options` is an object with the following keys and default values:
  • _all_lowercase: true_ - Transforms the local part (before the @ symbol) of all email addresses to lowercase. Please note that this may violate RFC 5321, which gives providers the possibility to treat the local part of email addresses in a case sensitive way (although in practice most - yet not all - providers don't). The domain part of the email address is always lowercased, as it's case insensitive per RFC 1035.
  • _gmail_lowercase: true_ - GMail addresses are known to be case-insensitive, so this switch allows lowercasing them even when _all_lowercase_ is set to false. Please note that when _all_lowercase_ is true, GMail addresses are lowercased regardless of the value of this setting.
  • _gmail_remove_dots: true_: Removes dots from the local part of the email address, as GMail ignores them (e.g. "john.doe" and "johndoe" are considered equal).
  • _gmail_remove_subaddress: true_: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@gmail.com" becomes "foo@gmail.com").
  • _gmail_convert_googlemaildotcom: true_: Converts addresses with domain @googlemail.com to @gmail.com, as they're equivalent.
  • _outlookdotcom_lowercase: true_ - Outlook.com addresses (including Windows Live and Hotmail) are known to be case-insensitive, so this switch allows lowercasing them even when _all_lowercase_ is set to false. Please note that when _all_lowercase_ is true, Outlook.com addresses are lowercased regardless of the value of this setting.
  • _outlookdotcom_remove_subaddress: true_: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@outlook.com" becomes "foo@outlook.com").
  • _yahoo_lowercase: true_ - Yahoo Mail addresses are known to be case-insensitive, so this switch allows lowercasing them even when _all_lowercase_ is set to false. Please note that when _all_lowercase_ is true, Yahoo Mail addresses are lowercased regardless of the value of this setting.
  • _yahoo_remove_subaddress: true_: Normalizes addresses by removing "sub-addresses", which is the part following a "-" sign (e.g. "foo-bar@yahoo.com" becomes "foo@yahoo.com").
  • _icloud_lowercase: true_ - iCloud addresses (including MobileMe) are known to be case-insensitive, so this switch allows lowercasing them even when _all_lowercase_ is set to false. Please note that when _all_lowercase_ is true, iCloud addresses are lowercased regardless of the value of this setting.
  • _icloud_remove_subaddress: true_: Normalizes addresses by removing "sub-addresses", which is the part following a "+" sign (e.g. "foo+bar@icloud.com" becomes "foo@icloud.com").
| +| **rtrim(input [, chars])** | trim characters from the right-side of the input. | +| **stripLow(input [, keep_new_lines])** | remove characters with a numerical value < 32 and 127, mostly control characters. If `keep_new_lines` is `true`, newline characters are preserved (`\n` and `\r`, hex `0xA` and `0xD`). Unicode-safe in JavaScript. | +| **toBoolean(input [, strict])** | convert the input string to a boolean. Everything except for `'0'`, `'false'` and `''` returns `true`. In strict mode only `'1'` and `'true'` return `true`. | +| **toDate(input)** | convert the input string to a date, or `null` if the input is not a date. | +| **toFloat(input)** | convert the input string to a float, or `NaN` if the input is not a float. | +| **toInt(input [, radix])** | convert the input string to an integer, or `NaN` if the input is not an integer. | +| **trim(input [, chars])** | trim characters (whitespace by default) from both sides of the input. | +| **whitelist(input, chars)** | remove characters that do not appear in the whitelist. The characters are used in a RegExp and so you will need to escape some chars, e.g. `whitelist(input, '\\[\\]')`. | ### XSS Sanitization @@ -167,10 +168,10 @@ In general, we follow the "fork-and-pull" Git workflow. 1. Fork the repo on GitHub 2. Clone the project to your own machine 3. Work on your fork - 1. Make your changes and additions - 2. Change or add tests if needed - 3. Run tests and make sure they pass - 4. Add changes to README.md if needed + 1. Make your changes and additions + 2. Change or add tests if needed + 3. Run tests and make sure they pass + 4. Add changes to README.md if needed 4. Commit changes to your own branch 5. **Make sure** you merge the latest from "upstream" and resolve conflicts if there is any 6. Repeat step 3(3) above @@ -220,15 +221,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` [downloads-image]: http://img.shields.io/npm/dm/validator.svg - [npm-url]: https://npmjs.org/package/validator [npm-image]: http://img.shields.io/npm/v/validator.svg - [travis-url]: https://travis-ci.org/chriso/validator.js [travis-image]: http://img.shields.io/travis/chriso/validator.js.svg - [amd]: http://requirejs.org/docs/whyamd.html [bower]: http://bower.io/ - [mongoid]: http://docs.mongodb.org/manual/reference/object-id/ -[ISIN]: https://en.wikipedia.org/wiki/International_Securities_Identification_Number +[isin]: https://en.wikipedia.org/wiki/International_Securities_Identification_Number diff --git a/index.js b/index.js index 478b56865..6b36368a7 100644 --- a/index.js +++ b/index.js @@ -151,6 +151,8 @@ 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 }; } @@ -235,7 +237,9 @@ var validator = { blacklist: _blacklist.default, isWhitelisted: _isWhitelisted.default, normalizeEmail: _normalizeEmail.default, - toString: _toString.default + 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..93c6de883 --- /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}$/, + BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/, + BE: /^(BE[0-9]{2})\d{12}$/, + BA: /^(BA[0-9]{2})\d{16}$/, + BG: /^(BG[0-9]{2})[A-Z]{4}\d{4}[A-Z0-9]{10}$/, + 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}$/, + HU: /^(HU[0-9]{2})\d{24}$/, + HR: /^(HR[0-9]{2})\d{17}$/, + 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 10 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/lib/isMobilePhone.js b/lib/isMobilePhone.js index b72cddadc..14373b630 100644 --- a/lib/isMobilePhone.js +++ b/lib/isMobilePhone.js @@ -14,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var phones = { 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/, 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/, - 'ar-EG': /^((\+?20)|0)?1[012]\d{8}$/, + 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/, 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/, 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/, 'ar-KW': /^(\+?965)[569]\d{7}$/, @@ -48,6 +48,7 @@ var phones = { 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/, 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/, + 'es-PY': /^(\+?595|0)9[9876]\d{7}$/, 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/, 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/, 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/, diff --git a/lib/isPostalCode.js b/lib/isPostalCode.js index e10088211..8b2b07e30 100644 --- a/lib/isPostalCode.js +++ b/lib/isPostalCode.js @@ -35,6 +35,7 @@ var patterns = { GR: /^\d{3}\s?\d{2}$/, HR: /^([1-5]\d{4}$)/, HU: fourDigit, + ID: fiveDigit, IL: fiveDigit, IN: sixDigit, IS: threeDigit, diff --git a/src/index.js b/src/index.js index 4cb4d5188..51e2f1504 100644 --- a/src/index.js +++ b/src/index.js @@ -96,6 +96,8 @@ import normalizeEmail from './lib/normalizeEmail'; import toString from './lib/util/toString'; +import isIBAN, { locales as isIBANLocales } from './lib/isIBAN'; + const version = '10.11.0'; const validator = { @@ -178,6 +180,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..31d6b18e4 --- /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 10 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 cf7e04e73..10aaac2e8 100644 --- a/test/validators.js +++ b/test/validators.js @@ -15,7 +15,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); } @@ -27,7 +28,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); } @@ -61,7 +63,10 @@ describe('Validators', () => { '" foo m端ller "@example.com', '"foo\\@bar"@example.com', `${repeat('a', 64)}@${repeat('a', 63)}.com`, - `${repeat('a', 64)}@${repeat('a', 63)}.${repeat('a', 63)}.${repeat('a', 63)}.${repeat('a', 58)}.com`, + `${repeat('a', 64)}@${repeat('a', 63)}.${repeat('a', 63)}.${repeat('a', 63)}.${repeat( + 'a', + 58 + )}.com`, `${repeat('a', 64)}@${repeat('a', 63)}.com`, `${repeat('a', 31)}@gmail.com`, 'test@gmail.com', @@ -107,18 +112,11 @@ describe('Validators', () => { test({ validator: 'isEmail', args: [{ domain_specific_validation: true }], - valid: [ - 'foo@bar.com', - ], - invalid: [ - `${repeat('a', 31)}@gmail.com`, - 'test@gmail.com', - 'test.1@gmail.com', - ], + valid: ['foo@bar.com'], + invalid: [`${repeat('a', 31)}@gmail.com`, 'test@gmail.com', 'test.1@gmail.com'], }); }); - it('should validate email addresses without UTF8 characters in local part', () => { test({ validator: 'isEmail', @@ -172,7 +170,7 @@ describe('Validators', () => { 'Some Name ', 'Some Name ', 'Some Name ', - '\'Foo Bar, Esq\'', + "'Foo Bar, Esq'", 'Some Name ', 'Some Middle Name ', 'Name ', @@ -249,14 +247,8 @@ describe('Validators', () => { test({ validator: 'isEmail', args: [{ allow_ip_domain: true }], - valid: [ - 'email@[123.123.123.123]', - 'email@255.255.255.255', - ], - invalid: [ - 'email@0.0.0.256', - 'email@26.0.0.256', - ], + valid: ['email@[123.123.123.123]', 'email@255.255.255.255'], + invalid: ['email@0.0.0.256', 'email@26.0.0.256'], }); }); @@ -284,7 +276,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', @@ -342,7 +334,7 @@ describe('Validators', () => { 'http://localhost:61500this is an invalid url!!!!', '////foobar.com', 'http:////foobar.com', - 'https://example.com/foo//', + "https://example.com/foo//", ], }); }); @@ -350,61 +342,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/', @@ -417,16 +400,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: [], }); }); @@ -434,97 +413,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/', @@ -532,43 +491,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/', @@ -583,47 +531,28 @@ 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'], }); }); it('should validate MAC addresses', () => { test({ validator: 'isMACAddress', - valid: [ - 'ab:ab:ab:ab:ab:ab', - 'FF:FF:FF:FF:FF:FF', - '01:02:03:04:05:ab', - '01:AB:03:04:05:06', - ], - invalid: [ - 'abc', - '01:02:03:04:05', - '01:02:03:04::ab', - '1:2:3:4:5:6', - 'AB:CD:EF:GH:01:02', - ], + valid: ['ab:ab:ab:ab:ab:ab', 'FF:FF:FF:FF:FF:FF', '01:02:03:04:05:ab', '01:AB:03:04:05:06'], + invalid: ['abc', '01:02:03:04:05', '01:02:03:04::ab', '1:2:3:4:5:6', 'AB:CD:EF:GH:01:02'], }); }); 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', @@ -690,33 +619,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', @@ -736,11 +646,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', @@ -767,46 +673,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ß'], }); }); @@ -814,20 +696,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['bg-BG'], - valid: [ - 'абв', - 'АБВ', - 'жаба', - 'яГоДа', - ], - invalid: [ - 'abc1', - ' foo ', - '', - 'ЁЧПС', - '_аз_обичам_обувки_', - 'ехо!', - ], + valid: ['абв', 'АБВ', 'жаба', 'яГоДа'], + invalid: ['abc1', ' foo ', '', 'ЁЧПС', '_аз_обичам_обувки_', 'ехо!'], }); }); @@ -835,18 +705,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 ', ''], }); }); @@ -866,12 +726,7 @@ describe('Validators', () => { 'Ďábelské', 'ódy', ], - invalid: [ - '1moj', - '你好世界', - ' Привет мир ', - 'مرحبا العا ', - ], + invalid: ['1moj', '你好世界', ' Привет мир ', 'مرحبا العا '], }); }); @@ -879,17 +734,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', ''], }); }); @@ -897,18 +743,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'], }); }); @@ -916,17 +752,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öö ', ''], }); }); @@ -934,16 +761,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ß', ''], }); }); @@ -961,12 +780,7 @@ describe('Validators', () => { 'PÉSCA', 'genî', ], - invalid: [ - 'äbc123', - 'ÄBC11', - 'æøå', - '', - ], + invalid: ['äbc123', 'ÄBC11', 'æøå', ''], }); }); @@ -974,21 +788,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ß'], }); }); @@ -996,21 +797,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ß'], }); }); @@ -1018,17 +806,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', ''], }); }); @@ -1036,20 +815,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!'], }); }); @@ -1057,15 +824,8 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['sr-RS'], - valid: [ - 'ШћжЂљЕ', - 'ЧПСТЋЏ', - ], - invalid: [ - 'řiď ', - 'blé33!!', - 'föö!!', - ], + valid: ['ШћжЂљЕ', 'ЧПСТЋЏ'], + invalid: ['řiď ', 'blé33!!', 'föö!!'], }); }); @@ -1073,15 +833,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!'], }); }); @@ -1089,18 +842,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öö!!'], }); }); @@ -1108,17 +851,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', ''], }); }); @@ -1126,21 +860,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ß'], }); }); @@ -1148,18 +869,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ß'], }); }); @@ -1167,9 +878,7 @@ describe('Validators', () => { test({ validator: 'isAlpha', args: ['uk-UA'], - valid: [ - 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ', - ], + valid: ['АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ'], invalid: [ '0AİıÖöÇ窺ĞğÜüZ1', ' AİıÖöÇ窺ĞğÜüZ ', @@ -1187,36 +896,16 @@ 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γ'], }); }); 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'], }); }); @@ -1224,17 +913,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'], }); }); @@ -1242,19 +922,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'], }); }); @@ -1262,14 +931,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é!!'], }); }); @@ -1289,11 +952,7 @@ describe('Validators', () => { '9Ďábelské', '10ódy', ], - invalid: [ - '1moj!', - '你好世界', - ' Привет мир ', - ], + invalid: ['1moj!', '你好世界', ' Привет мир '], }); }); @@ -1301,17 +960,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', ''], }); }); @@ -1319,18 +969,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'], }); }); @@ -1338,14 +978,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['de-DE'], - valid: [ - 'äbc123', - 'ÄBC11', - ], - invalid: [ - 'äca ', - 'föö!!', - ], + valid: ['äbc123', 'ÄBC11'], + invalid: ['äca ', 'föö!!'], }); }); @@ -1353,17 +987,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ß!', ''], }); }); @@ -1381,12 +1006,7 @@ describe('Validators', () => { 'PÉS45CA', 'gen45î', ], - invalid: [ - 'äbc123', - 'ÄBC11', - 'æøå', - '', - ], + invalid: ['äbc123', 'ÄBC11', 'æøå', ''], }); }); @@ -1394,15 +1014,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öö!!'], }); }); @@ -1410,15 +1023,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['ar'], - valid: [ - 'أبت123', - 'أبتَُِ١٢٣', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], + valid: ['أبت123', 'أبتَُِ١٢٣'], + invalid: ['äca ', 'abcß', 'föö!!'], }); }); @@ -1426,14 +1032,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['ku-IQ'], - valid: [ - 'ئؤڤگێ١٢٣', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], + valid: ['ئؤڤگێ١٢٣'], + invalid: ['äca ', 'abcß', 'föö!!'], }); }); @@ -1441,17 +1041,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'], }); }); @@ -1459,17 +1050,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', ''], }); }); @@ -1486,11 +1068,7 @@ describe('Validators', () => { 'świ23ęty', 'Poz1322wól', ], - invalid: [ - '12řiď ', - 'blé!!', - 'föö!2!', - ], + invalid: ['12řiď ', 'blé!!', 'föö!2!'], }); }); @@ -1498,15 +1076,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['sr-RS'], - valid: [ - 'ШћжЂљЕ123', - 'ЧПСТ132ЋЏ', - ], - invalid: [ - 'řiď ', - 'blé!!', - 'föö!!', - ], + valid: ['ШћжЂљЕ123', 'ЧПСТ132ЋЏ'], + invalid: ['řiď ', 'blé!!', 'föö!!'], }); }); @@ -1514,15 +1085,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öö!!'], }); }); @@ -1530,17 +1094,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!!', ''], }); }); @@ -1548,14 +1103,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'], }); }); @@ -1563,15 +1112,8 @@ describe('Validators', () => { test({ validator: 'isAlphanumeric', args: ['uk-UA'], - valid: [ - 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ123', - ], - invalid: [ - 'éeoc ', - 'foo!!', - 'ÄBC', - 'ЫыЪъЭэ', - ], + valid: ['АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ123'], + invalid: ['éeoc ', 'foo!!', 'ÄBC', 'ЫыЪъЭэ'], }); }); @@ -1579,20 +1121,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γ'], }); }); @@ -1608,65 +1138,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'], }); }); @@ -1873,13 +1367,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', @@ -1908,19 +1396,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', @@ -1948,156 +1424,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'], }); }); @@ -2118,14 +1506,7 @@ describe('Validators', () => { '01.123', '-0.22250738585072011e-307', ], - invalid: [ - '+', - '-', - ' ', - '', - '.', - 'foo', - ], + invalid: ['+', '-', ' ', '', '.', 'foo'], }); test({ @@ -2145,14 +1526,7 @@ describe('Validators', () => { '01.123', '-0.22250738585072011e-307', ], - invalid: [ - '123٫123', - '123,123', - ' ', - '', - '.', - 'foo', - ], + invalid: ['123٫123', '123,123', ' ', '', '.', 'foo'], }); test({ @@ -2172,14 +1546,7 @@ describe('Validators', () => { '01,123', '-0,22250738585072011e-307', ], - invalid: [ - '123.123', - '123٫123', - ' ', - '', - '.', - 'foo', - ], + invalid: ['123.123', '123٫123', ' ', '', '.', 'foo'], }); test({ @@ -2199,113 +1566,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', @@ -2330,50 +1647,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'], }); }); @@ -2386,12 +1677,7 @@ describe('Validators', () => { '88dae00e614d8f24cfd5a8b3f8002e93', '0bf1c35032a71a14c2f719e5a14c1e96', ], - invalid: [ - 'KYT0bf1c35032a71a14c2f719e5a14c1', - 'q94375dj93458w34', - '39485729348', - '%&FHKJFvk', - ], + invalid: ['KYT0bf1c35032a71a14c2f719e5a14c1', 'q94375dj93458w34', '39485729348', '%&FHKJFvk'], }); }); @@ -2405,22 +1691,12 @@ describe('Validators', () => { '88dae00e614d8f24cfd5a8b3f8002e93', '0bf1c35032a71a14c2f719e5a14c1e96', ], - invalid: [ - 'KYT0bf1c35032a71a14c2f719e5a14c1', - 'q94375dj93458w34', - '39485729348', - '%&FHKJFvk', - ], + invalid: ['KYT0bf1c35032a71a14c2f719e5a14c1', 'q94375dj93458w34', '39485729348', '%&FHKJFvk'], }); test({ validator: 'isHash', args: ['crc32', 'crc32b'], - valid: [ - 'd94f3f01', - '751adbc5', - '88dae00e', - '0bf1c350', - ], + valid: ['d94f3f01', '751adbc5', '88dae00e', '0bf1c350'], invalid: [ 'KYT0bf1c35032a71a14c2f719e5a14c1', 'q94375dj93458w34', @@ -2525,55 +1801,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'], }); }); @@ -2736,9 +1993,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', @@ -2863,11 +2118,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({ @@ -2888,13 +2139,7 @@ describe('Validators', () => { validator: 'isDivisibleBy', args: [2], valid: ['2', '4', '100', '1000'], - invalid: [ - '1', - '2.5', - '101', - 'foo', - '', - ], + invalid: ['1', '2.5', '101', 'foo', ''], }); }); @@ -2986,13 +2231,8 @@ describe('Validators', () => { // Test generics test({ validator: 'isIdentityCard', - valid: [ - ...allValid, - ], - invalid: [ - 'foo', - ...allInvalid, - ], + valid: [...allValid], + invalid: ['foo', ...allInvalid], args: ['any'], }); }); @@ -3009,12 +2249,7 @@ describe('Validators', () => { 'DE000WCH8881', 'PLLWBGD00016', ], - invalid: [ - 'DE000BAY0018', - 'PLLWBGD00019', - 'foo', - '5398228707871528', - ], + invalid: ['DE000BAY0018', 'PLLWBGD00019', 'foo', '5398228707871528'], }); }); @@ -3023,64 +2258,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', @@ -3096,62 +2342,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"'], }); }); @@ -3166,74 +2378,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', @@ -3248,16 +2424,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'], }); }); @@ -3275,12 +2443,12 @@ describe('Validators', () => { 'Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIHBvcnRhLg==', 'U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==', 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuMPNS1Ufof9EW/M98FNw' + - 'UAKrwflsqVxaxQjBQnHQmiI7Vac40t8x7pIb8gLGV6wL7sBTJiPovJ0V7y7oc0Ye' + - 'rhKh0Rm4skP2z/jHwwZICgGzBvA0rH8xlhUiTvcwDCJ0kc+fh35hNt8srZQM4619' + - 'FTgB66Xmp4EtVyhpQV+t02g6NzK72oZI0vnAvqhpkxLeLiMCyrI416wHm5Tkukhx' + - 'QmcL2a6hNOyu0ixX/x2kSFXApEnVrJ+/IxGyfyw8kf4N2IZpW5nEP847lpfj0SZZ' + - 'Fwrd1mnfnDbYohX2zRptLy2ZUn06Qo9pkG5ntvFEPo9bfZeULtjYzIl6K8gJ2uGZ' + - 'HQIDAQAB', + 'UAKrwflsqVxaxQjBQnHQmiI7Vac40t8x7pIb8gLGV6wL7sBTJiPovJ0V7y7oc0Ye' + + 'rhKh0Rm4skP2z/jHwwZICgGzBvA0rH8xlhUiTvcwDCJ0kc+fh35hNt8srZQM4619' + + 'FTgB66Xmp4EtVyhpQV+t02g6NzK72oZI0vnAvqhpkxLeLiMCyrI416wHm5Tkukhx' + + 'QmcL2a6hNOyu0ixX/x2kSFXApEnVrJ+/IxGyfyw8kf4N2IZpW5nEP847lpfj0SZZ' + + 'Fwrd1mnfnDbYohX2zRptLy2ZUn06Qo9pkG5ntvFEPo9bfZeULtjYzIl6K8gJ2uGZ' + + 'HQIDAQAB', ], invalid: [ '12345', @@ -3294,7 +2462,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); @@ -3306,9 +2474,7 @@ describe('Validators', () => { it('should validate hex-encoded MongoDB ObjectId', () => { test({ validator: 'isMongoId', - valid: [ - '507f1f77bcf86cd799439011', - ], + valid: ['507f1f77bcf86cd799439011'], invalid: [ '507f1f77bcf86cd7994390', '507f1f77bcf86cd79943901z', @@ -3445,117 +2611,38 @@ 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', - valid: [ - '+8801794626846', - '01399098893', - '8801671163269', - '01717112029', - ], - invalid: [ - '', - '0174626346', - '017943563469', - '18001234567', - '01494676946', - ], + valid: ['+8801794626846', '01399098893', '8801671163269', '01717112029'], + invalid: ['', '0174626346', '017943563469', '18001234567', '01494676946'], }, { 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', @@ -3644,42 +2731,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', @@ -3713,12 +2775,7 @@ describe('Validators', () => { '+233232345671', '+233282345671', ], - invalid: [ - '082123', - '232345671', - '0292345671', - '+233292345671', - ], + invalid: ['082123', '232345671', '0292345671', '+233292345671'], }, { locale: 'en-HK', @@ -3732,12 +2789,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', @@ -3752,80 +2804,27 @@ describe('Validators', () => { '0871234567', '0851234567', ], - invalid: [ - '999', - '+353341234567', - '+33589484858', - '353841234567', - '353811234567', - ], + invalid: ['999', '+353341234567', '+33589484858', '353841234567', '353811234567'], }, { locale: 'en-KE', - valid: [ - '+254728590432', - '+254733875610', - '254728590234', - '0733346543', - '0700459022', - ], - invalid: [ - '999', - '+25489032', - '123456789', - '+254800723845', - ], + valid: ['+254728590432', '+254733875610', '254728590234', '0733346543', '0700459022'], + invalid: ['999', '+25489032', '123456789', '+254800723845'], }, { 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', @@ -3854,11 +2853,7 @@ describe('Validators', () => { }, { locale: 'el-GR', - valid: [ - '+306944848966', - '6944848966', - '306944848966', - ], + valid: ['+306944848966', '6944848966', '306944848966'], invalid: [ '2102323234', '+302646041461', @@ -3871,11 +2866,7 @@ describe('Validators', () => { }, { locale: 'en-GB', - valid: [ - '447789345856', - '+447861235675', - '07888814488', - ], + valid: ['447789345856', '+447861235675', '07888814488'], invalid: [ '67699567', '0773894868', @@ -3890,12 +2881,7 @@ describe('Validators', () => { }, { locale: 'en-SG', - valid: [ - '87654321', - '98765432', - '+6587654321', - '+6598765432', - ], + valid: ['87654321', '98765432', '+6587654321', '+6598765432'], invalid: [ '987654321', '876543219', @@ -3937,13 +2923,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', @@ -3956,22 +2936,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', '', @@ -4006,12 +2975,7 @@ describe('Validators', () => { }, { locale: 'en-NZ', - valid: [ - '+6427987035', - '642240512347', - '0293981646', - '029968425', - ], + valid: ['+6427987035', '642240512347', '0293981646', '029968425'], invalid: [ '12345', '', @@ -4026,11 +2990,7 @@ describe('Validators', () => { }, { locale: 'en-MU', - valid: [ - '+23012341234', - '12341234', - '012341234', - ], + valid: ['+23012341234', '12341234', '012341234'], invalid: [ '41234', '', @@ -4049,14 +3009,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', '', @@ -4070,13 +3023,7 @@ describe('Validators', () => { }, { locale: 'vi-VN', - valid: [ - '0336012403', - '+84586012403', - '84981577798', - '0708001240', - '84813601243', - ], + valid: ['0336012403', '+84586012403', '84981577798', '0708001240', '84813601243'], invalid: [ '12345', '', @@ -4177,20 +3124,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', @@ -4350,11 +3285,7 @@ describe('Validators', () => { }, { locale: 'ja-JP', - valid: [ - '09012345688', - '090 123 45678', - '+8190-123-45678', - ], + valid: ['09012345688', '090 123 45678', '+8190-123-45678'], invalid: [ '12345', '', @@ -4379,17 +3310,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', @@ -4539,198 +3461,624 @@ describe('Validators', () => { ], }, { - locale: 'lt-LT', - valid: [ - '+37051234567', - '851234567', - ], + locale: 'lt-LT', + valid: ['+37051234567', '851234567'], + invalid: [ + '+65740 123 456', + '', + 'ASDFGJKLmZXJtZtesting123', + '123456', + '740123456', + '+65640123456', + '+64210123456', + ], + }, + { + 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: [ + 'LB62099900000001001901229119', + 'LB6209A900000001001901229114', + 'LB620999000000010019012291149', + ], + }, + { + 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: [ + 'MD24AG000225100013104169', + 'MD24A9000225100013104168', + 'MD24AG0002251000131041689', + ], + }, + { + locale: 'ME', + valid: ['ME25505000012345678951'], + invalid: ['ME25505000012345678959', 'ME2550500001234567895A', 'ME255050000123456789519'], + }, + { + locale: 'MK', + valid: ['MK07250120000058984'], + invalid: ['MK07250120000058989', 'MK07A50120000058984', 'MK072501200000589849'], + }, + { + locale: 'MT', + valid: ['MT84MALT011000012345MTLCAST001S'], invalid: [ - '+65740 123 456', - '', - 'ASDFGJKLmZXJtZtesting123', - '123456', - '740123456', - '+65640123456', - '+64210123456', + 'MT84MALT011000012345MTLCAST0019', + 'MT84M9LT011000012345MTLCAST001S', + 'MT84MALT0A1000012345MTLCAST001S', + 'MT84MALT011000012345MTLCAST001S9', ], }, { - locale: 'uk-UA', - valid: [ - '+380982345679', - '380982345679', - '80982345679', - '0982345679', - ], + locale: 'NL', + valid: ['NL91ABNA0417164300'], invalid: [ - '+30982345679', - '982345679', - '+380 98 234 5679', - '+380-98-234-5679', - '', - 'ASDFGJKLmZXJtZtesting123', - '123456', - '740123456', + 'NL91ABNA0417164309', + 'NL91AB9A0417164300', + 'NL91ABNA041716430A', + 'NL91ABNA04171643009', ], }, { - locale: 'da-DK', - valid: [ - '12345678', - '12 34 56 78', - '45 12345678', - '4512345678', - '45 12 34 56 78', - '+45 12 34 56 78', - ], + locale: 'NO', + valid: ['NO9386011117947'], + invalid: ['NO9386011117949', 'NO938601111794A', 'NO93860111179479'], + }, + { + locale: 'PL', + valid: ['PL61109010140000071219812874'], invalid: [ - '', - '+45010203', - 'ASDFGJKLmZXJtZtesting123', - '123456', - '12 34 56', - '123 123 12', + 'PL61109010140000071219812879', + 'PL6110901014000007121981287A', + 'PL611090101400000712198128749', ], }, { - locale: 'sv-SE', - valid: [ - '+46701234567', - '46701234567', - '0721234567', - '073-1234567', - '0761-234567', - '079-123 45 67', - ], + locale: 'PS', + valid: ['PS92PALS000000000400123456702'], invalid: [ - '12345', - '+4670123456', - '+46301234567', - '+0731234567', - '0731234 56', - '+7312345678', - '', + 'PS92PALS000000000400123456709', + 'PS92P9LS000000000400123456702', + 'PS92PALS0000000004001234567029', ], }, { - locale: 'fo-FO', - valid: [ - '123456', - '12 34 56', - '298 123456', - '298123456', - '298 12 34 56', - '+298 12 34 56', - ], + locale: 'PT', + valid: ['PT50000201231234567890154'], invalid: [ - '', - '+4501020304', - 'ASDFGJKLmZXJtZtesting123', - '12345678', - '12 34 56 78', + 'PT50000201231234567890159', + 'PT5000020123123456789015A', + 'PT500002012312345678901549', ], }, { - locale: 'kl-GL', - valid: [ - '123456', - '12 34 56', - '299 123456', - '299123456', - '299 12 34 56', - '+299 12 34 56', - ], + 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 = []; @@ -4739,62 +4087,26 @@ 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: [ - '', - 'asdf', - '1', - 'ASDFGJKLmZXJtZtesting123', - 'Vml2YW11cyBmZXJtZtesting123', - ], + 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', + validator: 'isIBAN', valid: allValid, - invalid: [ - '', - 'asdf', - '1', - 'ASDFGJKLmZXJtZtesting123', - 'Vml2YW11cyBmZXJtZtesting123', - ], + invalid: ['', 'asdf', '1', 'ASDFGJKLmZXJtZtesting123', 'Vml2YW11cyBmZXJtZtesting123'], args: [], }); }); @@ -4802,10 +4114,7 @@ describe('Validators', () => { it('should validate currency', () => { test({ validator: 'isCurrency', - args: [ - {}, - '-$##,###.## (en-US, en-CA, en-AU, en-NZ, en-HK)', - ], + args: [{}, '-$##,###.## (en-US, en-CA, en-AU, en-NZ, en-HK)'], valid: [ '-$10,123.45', '$10,123.45', @@ -5654,20 +4963,8 @@ describe('Validators', () => { 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'], }); }); @@ -5754,9 +5051,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, }); @@ -5765,19 +5060,9 @@ describe('Validators', () => { it('should validate ISO 8601 dates, with strict = true', () => { test({ validator: 'isISO8601', - args: [ - { strict: true }, - ], - valid: [ - '2000-02-29', - '2009-123', - '2009-222', - ], - invalid: [ - '2010-02-30', - '2009-02-29', - '2009-366', - ], + args: [{ strict: true }], + valid: ['2000-02-29', '2009-123', '2009-222'], + invalid: ['2010-02-30', '2009-02-29', '2009-366'], }); }); @@ -5820,30 +5105,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'], }); }); @@ -5851,23 +5114,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'], }); }); @@ -5908,7 +5156,8 @@ describe('Validators', () => { 'dataxbase64', 'data:HelloWorld', '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', @@ -5918,7 +5167,6 @@ describe('Validators', () => { /* eslint-enable max-len */ }); - it('should validate magnetURI', () => { /* eslint-disable max-len */ test({ @@ -5950,7 +5198,6 @@ describe('Validators', () => { /* eslint-enable max-len */ }); - it('should validate LatLong', () => { test({ validator: 'isLatLong', @@ -6014,43 +5261,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', @@ -6072,116 +5295,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'], }, ]; diff --git a/validator.js b/validator.js index 7a32e3bb2..02c922daf 100644 --- a/validator.js +++ b/validator.js @@ -40,191 +40,6 @@ function _typeof(obj) { return _typeof(obj); } -function _toArray(arr) { - return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); -} - -function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; -} - -function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); -} - -function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance"); -} - -function _toPrimitive(input, hint) { - if (typeof input !== "object" || input === null) return input; - var prim = input[Symbol.toPrimitive]; - - if (prim !== undefined) { - var res = prim.call(input, hint || "default"); - if (typeof res !== "object") return res; - throw new TypeError("@@toPrimitive must return a primitive value."); - } - - return (hint === "string" ? String : Number)(input); -} - -function _toPropertyKey(arg) { - var key = _toPrimitive(arg, "string"); - - return typeof key === "symbol" ? key : String(key); -} - -function _addElementPlacement(element, placements, silent) { - var keys = placements[element.placement]; - - if (!silent && keys.indexOf(element.key) !== -1) { - throw new TypeError("Duplicated element (" + element.key + ")"); - } - - keys.push(element.key); -} - -function _fromElementDescriptor(element) { - var obj = { - kind: element.kind, - key: element.key, - placement: element.placement, - descriptor: element.descriptor - }; - var desc = { - value: "Descriptor", - configurable: true - }; - Object.defineProperty(obj, Symbol.toStringTag, desc); - if (element.kind === "field") obj.initializer = element.initializer; - return obj; -} - -function _toElementDescriptors(elementObjects) { - if (elementObjects === undefined) return; - return _toArray(elementObjects).map(function (elementObject) { - var element = _toElementDescriptor(elementObject); - - _disallowProperty(elementObject, "finisher", "An element descriptor"); - - _disallowProperty(elementObject, "extras", "An element descriptor"); - - return element; - }); -} - -function _toElementDescriptor(elementObject) { - var kind = String(elementObject.kind); - - if (kind !== "method" && kind !== "field") { - throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"'); - } - - var key = _toPropertyKey(elementObject.key); - - var placement = String(elementObject.placement); - - if (placement !== "static" && placement !== "prototype" && placement !== "own") { - throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"'); - } - - var descriptor = elementObject.descriptor; - - _disallowProperty(elementObject, "elements", "An element descriptor"); - - var element = { - kind: kind, - key: key, - placement: placement, - descriptor: Object.assign({}, descriptor) - }; - - if (kind !== "field") { - _disallowProperty(elementObject, "initializer", "A method descriptor"); - } else { - _disallowProperty(descriptor, "get", "The property descriptor of a field descriptor"); - - _disallowProperty(descriptor, "set", "The property descriptor of a field descriptor"); - - _disallowProperty(descriptor, "value", "The property descriptor of a field descriptor"); - - element.initializer = elementObject.initializer; - } - - return element; -} - -function _toElementFinisherExtras(elementObject) { - var element = _toElementDescriptor(elementObject); - - var finisher = _optionalCallableProperty(elementObject, "finisher"); - - var extras = _toElementDescriptors(elementObject.extras); - - return { - element: element, - finisher: finisher, - extras: extras - }; -} - -function _fromClassDescriptor(elements) { - var obj = { - kind: "class", - elements: elements.map(_fromElementDescriptor) - }; - var desc = { - value: "Descriptor", - configurable: true - }; - Object.defineProperty(obj, Symbol.toStringTag, desc); - return obj; -} - -function _toClassDescriptor(obj) { - var kind = String(obj.kind); - - if (kind !== "class") { - throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"'); - } - - _disallowProperty(obj, "key", "A class descriptor"); - - _disallowProperty(obj, "placement", "A class descriptor"); - - _disallowProperty(obj, "descriptor", "A class descriptor"); - - _disallowProperty(obj, "initializer", "A class descriptor"); - - _disallowProperty(obj, "extras", "A class descriptor"); - - var finisher = _optionalCallableProperty(obj, "finisher"); - - var elements = _toElementDescriptors(obj.elements); - - return { - elements: elements, - finisher: finisher - }; -} - -function _disallowProperty(obj, name, objectType) { - if (obj[name] !== undefined) { - throw new TypeError(objectType + " can't have a ." + name + " property."); - } -} - -function _optionalCallableProperty(obj, name) { - var value = obj[name]; - - if (value !== undefined && typeof value !== "function") { - throw new TypeError("Expected '" + name + "' to be a function"); - } - - return value; -} - function assertString(input) { var isString = typeof input === 'string' || input instanceof String; @@ -887,14 +702,14 @@ function isNumeric(str, options) { return numeric.test(str); } -var int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/; +var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/; var intLeadingZeroes = /^[-+]?[0-9]+$/; function isInt(str, options) { assertString(str); options = options || {}; // Get the regex to use for testing, based on whether // leading zeroes are allowed or not. - var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? int : intLeadingZeroes; // Check min/max/lt/gt + var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? _int : intLeadingZeroes; // Check min/max/lt/gt var minCheckPassed = !options.hasOwnProperty('min') || str >= options.min; var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max; @@ -966,14 +781,15 @@ function isSurrogatePair(str) { function isFloat(str, options) { assertString(str); options = options || {}; - var float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$")); + + var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$")); if (str === '' || str === '.' || str === '-' || str === '+') { return false; } var value = parseFloat(str.replace(',', '.')); - return float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt); + return _float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt); } var locales$2 = Object.keys(decimal); @@ -1219,8 +1035,8 @@ var validators = { } // validate the control digit - var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (char) { - return charsValue[char]; + var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) { + return charsValue[_char]; }); return sanitized.endsWith(controlDigits[number % 23]); } @@ -1365,7 +1181,7 @@ function isISSN(str) { var phones = { 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/, 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/, - 'ar-EG': /^((\+?20)|0)?1[012]\d{8}$/, + 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/, 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/, 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/, 'ar-KW': /^(\+?965)[569]\d{7}$/, @@ -1399,6 +1215,7 @@ var phones = { 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/, 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/, + 'es-PY': /^(\+?595|0)9[9876]\d{7}$/, 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/, 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/, 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/, @@ -1729,12 +1546,12 @@ function isMimeType(str) { } var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; -var long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; +var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; var isLatLong = function (str) { assertString(str); if (!str.includes(',')) return false; var pair = str.split(','); - return lat.test(pair[0]) && long.test(pair[1]); + return lat.test(pair[0]) && _long.test(pair[1]); }; var threeDigit = /^\d{3}$/; @@ -1761,6 +1578,7 @@ var patterns = { GR: /^\d{3}\s?\d{2}$/, HR: /^([1-5]\d{4}$)/, HU: fourDigit, + ID: fiveDigit, IL: fiveDigit, IN: sixDigit, IS: threeDigit, @@ -2010,6 +1828,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}$/, + BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/, + BE: /^(BE[0-9]{2})\d{12}$/, + BA: /^(BA[0-9]{2})\d{16}$/, + BG: /^(BG[0-9]{2})[A-Z]{4}\d{4}[A-Z0-9]{10}$/, + 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}$/, + HU: /^(HU[0-9]{2})\d{24}$/, + HR: /^(HR[0-9]{2})\d{17}$/, + 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 10 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 = '10.11.0'; var validator = { version: version, @@ -2090,7 +2024,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 8fbfc7f4c..d07894607 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){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 n(t){return g(t),t=Date.parse(t),isNaN(t)?null:new Date(t)}function r(t){return g(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 h(){var t=0i)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(r.shift(),r.shift(),o=!0):"::"===t.substr(t.length-2)&&(r.pop(),r.pop(),o=!0);for(var a=0;a$/i,F=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,S=/^[a-z\d]+$/,R=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,E=/^[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,n=!e.hasOwnProperty("max")||t<=e.max,i=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&o&&n&&i&&a}var z=/^[\x00-\x7F]+$/;var W=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var Y=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var V=/[^\x00-\x7F]/;var j=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;var J=Object.keys(w),q=function(t,e){return t.some(function(t){return e===t})};var Q={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},X=["","-","+"];var tt=/^[0-9A-F]+$/i;function et(t){return g(t),tt.test(t)}var rt=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;var ot=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var nt=/^[a-f0-9]{32}$/;var it={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 at=/^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/;var lt={ignore_whitespace:!1};var st={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 ut=/^(?: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 ct={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 o=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"][o%23])}};var dt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var ft=/^(?:[0-9]{9}X|[0-9]{10})$/,pt=/^(?:[0-9]{13})$/,gt=[1,3];var ht={"ar-AE":/^((\+?971)|0)?5[024568]\d{7}$/,"ar-DZ":/^(\+?213|0)(5|6|7)\d{8}$/,"ar-EG":/^((\+?20)|0)?1[012]\d{8}$/,"ar-IQ":/^(\+?964|0)?7[0-9]\d{8}$/,"ar-JO":/^(\+?962|0)?7[789]\d{7}$/,"ar-KW":/^(\+?965)[569]\d{7}$/,"ar-SA":/^(!?(\+?966)|0)?5\d{8}$/,"ar-SY":/^(!?(\+?963)|0)?9\d{8}$/,"ar-TN":/^(\+?216)?[2459]\d{7}$/,"be-BY":/^(\+?375)?(24|25|29|33|44)\d{7}$/,"bg-BG":/^(\+?359|0)?8[789]\d{7}$/,"bn-BD":/\+?(88)?0?1[356789][0-9]{8}\b/,"cs-CZ":/^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,"da-DK":/^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,"de-DE":/^(\+49)?0?1(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,"el-GR":/^(\+?30|0)?(69\d{8})$/,"en-AU":/^(\+?61|0)4\d{8}$/,"en-GB":/^(\+?44|0)7\d{9}$/,"en-GH":/^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,"en-HK":/^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,"en-IE":/^(\+?353|0)8[356789]\d{7}$/,"en-IN":/^(\+?91|0)?[6789]\d{9}$/,"en-KE":/^(\+?254|0)?[7]\d{8}$/,"en-MU":/^(\+?230|0)?\d{8}$/,"en-NG":/^(\+?234|0)?[789]\d{9}$/,"en-NZ":/^(\+?64|0)[28]\d{7,9}$/,"en-PK":/^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,"en-RW":/^(\+?250|0)?[7]\d{8}$/,"en-SG":/^(\+65)?[89]\d{7}$/,"en-TZ":/^(\+?255|0)?[67]\d{8}$/,"en-UG":/^(\+?256|0)?[7]\d{8}$/,"en-US":/^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,"en-ZA":/^(\+?27|0)\d{9}$/,"en-ZM":/^(\+?26)?09[567]\d{7}$/,"es-ES":/^(\+?34)?(6\d{1}|7[1234])\d{7}$/,"es-MX":/^(\+?52)?(1|01)?\d{10,11}$/,"es-UY":/^(\+598|0)9[1-9][\d]{6}$/,"et-EE":/^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,"fa-IR":/^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,"fi-FI":/^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,"fo-FO":/^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,"fr-FR":/^(\+?33|0)[67]\d{8}$/,"he-IL":/^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,"hu-HU":/^(\+?36)(20|30|70)\d{7}$/,"id-ID":/^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,"it-IT":/^(\+?39)?\s?3\d{2} ?\d{6,7}$/,"ja-JP":/^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,"kk-KZ":/^(\+?7|8)?7\d{9}$/,"kl-GL":/^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,"ko-KR":/^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,"lt-LT":/^(\+370|8)\d{8}$/,"ms-MY":/^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,"nb-NO":/^(\+?47)?[49]\d{7}$/,"nl-BE":/^(\+?32|0)4?\d{8}$/,"nn-NO":/^(\+?47)?[49]\d{7}$/,"pl-PL":/^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,"pt-BR":/(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,"pt-PT":/^(\+?351)?9[1236]\d{7}$/,"ro-RO":/^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/,"sl-SI":/^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,"sk-SK":/^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,"sr-RS":/^(\+3816|06)[- \d]{5,9}$/,"sv-SE":/^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,"th-TH":/^(\+66|66|0)\d{9}$/,"tr-TR":/^(\+?90|0)?5\d{9}$/,"uk-UA":/^(\+?38|8)?0\d{9}$/,"vi-VN":/^(\+?84|0)((3([2-9]))|(5([689]))|(7([0|6-9]))|(8([1-5]))|(9([0-9])))([0-9]{7})$/,"zh-CN":/^((\+|00)86)?1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/,"zh-TW":/^(\+?886\-?|0)?9\d{8}$/};ht["en-CA"]=ht["en-US"],ht["fr-BE"]=ht["nl-BE"],ht["zh-HK"]=ht["en-HK"];var At=Object.keys(ht);var mt={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_decimal:!0,require_decimal:!1,digits_after_decimal:[2],allow_space_after_digits:!1};var $t=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;var vt=/([01][0-9]|2[0-3])/,_t=/[0-5][0-9]/,Ft=new RegExp("[-+]".concat(vt.source,":").concat(_t.source)),St=new RegExp("([zZ]|".concat(Ft.source,")")),Rt=new RegExp("".concat(vt.source,":").concat(_t.source,":").concat(/([0-5][0-9]|60)/.source).concat(/(\.[0-9]+)?/.source)),Et=new RegExp("".concat(/[0-9]{4}/.source,"-").concat(/(0[1-9]|1[0-2])/.source,"-").concat(/([12]\d|0[1-9]|3[01])/.source)),Ct=new RegExp("".concat(Rt.source).concat(St.source)),xt=new RegExp("".concat(Et.source,"[ tT]").concat(Ct.source));var Mt=["AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CW","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IR","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","ZA","ZM","ZW"];var Nt=["AFG","ALA","ALB","DZA","ASM","AND","AGO","AIA","ATA","ATG","ARG","ARM","ABW","AUS","AUT","AZE","BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BES","BIH","BWA","BVT","BRA","IOT","BRN","BGR","BFA","BDI","KHM","CMR","CAN","CPV","CYM","CAF","TCD","CHL","CHN","CXR","CCK","COL","COM","COG","COD","COK","CRI","CIV","HRV","CUB","CUW","CYP","CZE","DNK","DJI","DMA","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FLK","FRO","FJI","FIN","FRA","GUF","PYF","ATF","GAB","GMB","GEO","DEU","GHA","GIB","GRC","GRL","GRD","GLP","GUM","GTM","GGY","GIN","GNB","GUY","HTI","HMD","VAT","HND","HKG","HUN","ISL","IND","IDN","IRN","IRQ","IRL","IMN","ISR","ITA","JAM","JPN","JEY","JOR","KAZ","KEN","KIR","PRK","KOR","KWT","KGZ","LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","MAC","MKD","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MTQ","MRT","MUS","MYT","MEX","FSM","MDA","MCO","MNG","MNE","MSR","MAR","MOZ","MMR","NAM","NRU","NPL","NLD","NCL","NZL","NIC","NER","NGA","NIU","NFK","MNP","NOR","OMN","PAK","PLW","PSE","PAN","PNG","PRY","PER","PHL","PCN","POL","PRT","PRI","QAT","REU","ROU","RUS","RWA","BLM","SHN","KNA","LCA","MAF","SPM","VCT","WSM","SMR","STP","SAU","SEN","SRB","SYC","SLE","SGP","SXM","SVK","SVN","SLB","SOM","ZAF","SGS","SSD","ESP","LKA","SDN","SUR","SJM","SWZ","SWE","CHE","SYR","TWN","TJK","TZA","THA","TLS","TGO","TKL","TON","TTO","TUN","TUR","TKM","TCA","TUV","UGA","UKR","ARE","GBR","USA","UMI","URY","UZB","VUT","VEN","VNM","VGB","VIR","WLF","ESH","YEM","ZMB","ZWE"];var wt=/[^A-Z0-9+\/=]/i;var Lt=/^[a-z]+\/[a-z0-9\-\+]+$/i,It=/^[a-z\-]+=[a-z0-9\-]+$/i,Tt=/^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;var Zt=/^magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32,40}&dn=.+&tr=.+$/i;var Bt=/^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i,yt=/^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i,bt=/^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i;var Dt=/^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/,Ut=/^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/,Ot=/^\d{4}$/,Gt=/^\d{5}$/,Pt=/^\d{6}$/,kt={AD:/^AD\d{3}$/,AT:Ot,AU:Ot,BE:Ot,BG:Ot,CA:/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,CH:Ot,CZ:/^\d{3}\s?\d{2}$/,DE:Gt,DK:Ot,DZ:Gt,EE:Gt,ES:Gt,FI:Gt,FR:/^\d{2}\s?\d{3}$/,GB:/^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,GR:/^\d{3}\s?\d{2}$/,HR:/^([1-5]\d{4}$)/,HU:Ot,IL:Gt,IN:Pt,IS:/^\d{3}$/,IT:Gt,JP:/^\d{3}\-\d{4}$/,KE:Gt,LI:/^(948[5-9]|949[0-7])$/,LT:/^LT\-\d{5}$/,LU:Ot,LV:/^LV\-\d{4}$/,MX:Gt,NL:/^\d{4}\s?[a-z]{2}$/i,NO:Ot,PL:/^\d{2}\-\d{3}$/,PT:/^\d{4}\-\d{3}?$/,RO:Pt,RU:Pt,SA:Gt,SE:/^\d{3}\s?\d{2}$/,SI:Ot,SK:/^\d{3}\s?\d{2}$/,TN:Ot,TW:/^\d{3}(\d{2})?$/,UA:Gt,US:/^\d{5}(-\d{4})?$/,ZA:Ot,ZM:Gt},Kt=Object.keys(kt);function Ht(t,e){g(t);var r=e?new RegExp("^[".concat(e,"]+"),"g"):/^\s+/g;return t.replace(r,"")}function zt(t,e){g(t);for(var r=e?new RegExp("[".concat(e,"]")):/\s/,o=t.length-1;0<=o&&r.test(t[o]);o--);return o]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,o,n,i,a,l,s,u;if(e=h(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<=(o=s.shift()).indexOf(":")&&2=e.min)&&(!e.hasOwnProperty("max")||o<=e.max)&&(!e.hasOwnProperty("lt")||oe.gt)},isFloatLocales:J,isDecimal:function(t,e){if(g(t),(e=h(e,Q)).locale in w)return!q(X,t.replace(/ /g,""))&&(r=e,new RegExp("^[-+]?([0-9]+)?(\\".concat(w[r.locale],"[0-9]{").concat(r.decimal_digits,"})").concat(r.force_decimal?"":"?","$"))).test(t);var r;throw new Error("Invalid locale '".concat(e.locale,"'"))},isHexadecimal:et,isDivisibleBy:function(t,e){return g(t),r(t)%parseInt(e,10)==0},isHexColor:function(t){return g(t),rt.test(t)},isISRC:function(t){return g(t),ot.test(t)},isMD5:function(t){return g(t),nt.test(t)},isHash:function(t,e){return g(t),new RegExp("^[a-f0-9]{".concat(it[e],"}$")).test(t)},isJWT:function(t){return g(t),at.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=h(e,lt)).ignore_whitespace?t.trim().length:t.length)},isLength:function(t,e){var r,o;g(t),o="object"===a(e)?(r=e.min||0,e.max):(r=e,arguments[2]);var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return r<=i&&(void 0===o||i<=o)},isByteLength:A,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),Wt(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:Wt,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=h(e,Yt);var r=t.split("@"),o=r.pop(),n=[r.join("@"),o];if(n[1]=n[1].toLowerCase(),"gmail.com"===n[1]||"googlemail.com"===n[1]){if(e.gmail_remove_subaddress&&(n[0]=n[0].split("+")[0]),e.gmail_remove_dots&&(n[0]=n[0].replace(/\.+/g,Qt)),!n[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(n[0]=n[0].toLowerCase()),n[1]=e.gmail_convert_googlemaildotcom?"gmail.com":n[1]}else if(0<=Vt.indexOf(n[1])){if(e.icloud_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(n[0]=n[0].toLowerCase())}else if(0<=jt.indexOf(n[1])){if(e.outlookdotcom_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(n[0]=n[0].toLowerCase())}else if(0<=Jt.indexOf(n[1])){if(e.yahoo_remove_subaddress){var i=n[0].split("-");n[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,F=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,S=/^[a-z\d]+$/,Z=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,E=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,R=/^([\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 z=/^[\x00-\x7F]+$/;var W=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var Y=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var V=/[^\x00-\x7F]/;var j=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function J(t,e){return t.some(function(t){return e===t})}var q=Object.keys(C);var Q={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},X=["","-","+"];var tt=/^[0-9A-F]+$/i;function et(t){return $(t),tt.test(t)}var rt=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;var nt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var ot=/^[a-f0-9]{32}$/;var it={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 at=/^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/;var lt={ignore_whitespace:!1};var st={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 ut=/^(?: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 ct={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])}};var dt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var ft=/^(?:[0-9]{9}X|[0-9]{10})$/,At=/^(?:[0-9]{13})$/,$t=[1,3];var pt={"ar-AE":/^((\+?971)|0)?5[024568]\d{7}$/,"ar-DZ":/^(\+?213|0)(5|6|7)\d{8}$/,"ar-EG":/^((\+?20)|0)?1[0125]\d{8}$/,"ar-IQ":/^(\+?964|0)?7[0-9]\d{8}$/,"ar-JO":/^(\+?962|0)?7[789]\d{7}$/,"ar-KW":/^(\+?965)[569]\d{7}$/,"ar-SA":/^(!?(\+?966)|0)?5\d{8}$/,"ar-SY":/^(!?(\+?963)|0)?9\d{8}$/,"ar-TN":/^(\+?216)?[2459]\d{7}$/,"be-BY":/^(\+?375)?(24|25|29|33|44)\d{7}$/,"bg-BG":/^(\+?359|0)?8[789]\d{7}$/,"bn-BD":/\+?(88)?0?1[356789][0-9]{8}\b/,"cs-CZ":/^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,"da-DK":/^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,"de-DE":/^(\+49)?0?1(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,"el-GR":/^(\+?30|0)?(69\d{8})$/,"en-AU":/^(\+?61|0)4\d{8}$/,"en-GB":/^(\+?44|0)7\d{9}$/,"en-GH":/^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,"en-HK":/^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,"en-IE":/^(\+?353|0)8[356789]\d{7}$/,"en-IN":/^(\+?91|0)?[6789]\d{9}$/,"en-KE":/^(\+?254|0)?[7]\d{8}$/,"en-MU":/^(\+?230|0)?\d{8}$/,"en-NG":/^(\+?234|0)?[789]\d{9}$/,"en-NZ":/^(\+?64|0)[28]\d{7,9}$/,"en-PK":/^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,"en-RW":/^(\+?250|0)?[7]\d{8}$/,"en-SG":/^(\+65)?[89]\d{7}$/,"en-TZ":/^(\+?255|0)?[67]\d{8}$/,"en-UG":/^(\+?256|0)?[7]\d{8}$/,"en-US":/^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,"en-ZA":/^(\+?27|0)\d{9}$/,"en-ZM":/^(\+?26)?09[567]\d{7}$/,"es-ES":/^(\+?34)?(6\d{1}|7[1234])\d{7}$/,"es-MX":/^(\+?52)?(1|01)?\d{10,11}$/,"es-PY":/^(\+?595|0)9[9876]\d{7}$/,"es-UY":/^(\+598|0)9[1-9][\d]{6}$/,"et-EE":/^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,"fa-IR":/^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,"fi-FI":/^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,"fo-FO":/^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,"fr-FR":/^(\+?33|0)[67]\d{8}$/,"he-IL":/^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,"hu-HU":/^(\+?36)(20|30|70)\d{7}$/,"id-ID":/^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,"it-IT":/^(\+?39)?\s?3\d{2} ?\d{6,7}$/,"ja-JP":/^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,"kk-KZ":/^(\+?7|8)?7\d{9}$/,"kl-GL":/^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,"ko-KR":/^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,"lt-LT":/^(\+370|8)\d{8}$/,"ms-MY":/^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,"nb-NO":/^(\+?47)?[49]\d{7}$/,"nl-BE":/^(\+?32|0)4?\d{8}$/,"nn-NO":/^(\+?47)?[49]\d{7}$/,"pl-PL":/^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,"pt-BR":/(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,"pt-PT":/^(\+?351)?9[1236]\d{7}$/,"ro-RO":/^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/,"sl-SI":/^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,"sk-SK":/^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,"sr-RS":/^(\+3816|06)[- \d]{5,9}$/,"sv-SE":/^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,"th-TH":/^(\+66|66|0)\d{9}$/,"tr-TR":/^(\+?90|0)?5\d{9}$/,"uk-UA":/^(\+?38|8)?0\d{9}$/,"vi-VN":/^(\+?84|0)((3([2-9]))|(5([689]))|(7([0|6-9]))|(8([1-5]))|(9([0-9])))([0-9]{7})$/,"zh-CN":/^((\+|00)86)?1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/,"zh-TW":/^(\+?886\-?|0)?9\d{8}$/};pt["en-CA"]=pt["en-US"],pt["fr-BE"]=pt["nl-BE"],pt["zh-HK"]=pt["en-HK"];var gt=Object.keys(pt);var ht={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_decimal:!0,require_decimal:!1,digits_after_decimal:[2],allow_space_after_digits:!1};var mt=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;var vt=/([01][0-9]|2[0-3])/,_t=/[0-5][0-9]/,Ft=new RegExp("[-+]".concat(vt.source,":").concat(_t.source)),St=new RegExp("([zZ]|".concat(Ft.source,")")),Zt=new RegExp("".concat(vt.source,":").concat(_t.source,":").concat(/([0-5][0-9]|60)/.source).concat(/(\.[0-9]+)?/.source)),Et=new RegExp("".concat(/[0-9]{4}/.source,"-").concat(/(0[1-9]|1[0-2])/.source,"-").concat(/([12]\d|0[1-9]|3[01])/.source)),Rt=new RegExp("".concat(Zt.source).concat(St.source)),Lt=new RegExp("".concat(Et.source,"[ tT]").concat(Rt.source));var It=["AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CW","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IR","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","ZA","ZM","ZW"];var Mt=["AFG","ALA","ALB","DZA","ASM","AND","AGO","AIA","ATA","ATG","ARG","ARM","ABW","AUS","AUT","AZE","BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BES","BIH","BWA","BVT","BRA","IOT","BRN","BGR","BFA","BDI","KHM","CMR","CAN","CPV","CYM","CAF","TCD","CHL","CHN","CXR","CCK","COL","COM","COG","COD","COK","CRI","CIV","HRV","CUB","CUW","CYP","CZE","DNK","DJI","DMA","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FLK","FRO","FJI","FIN","FRA","GUF","PYF","ATF","GAB","GMB","GEO","DEU","GHA","GIB","GRC","GRL","GRD","GLP","GUM","GTM","GGY","GIN","GNB","GUY","HTI","HMD","VAT","HND","HKG","HUN","ISL","IND","IDN","IRN","IRQ","IRL","IMN","ISR","ITA","JAM","JPN","JEY","JOR","KAZ","KEN","KIR","PRK","KOR","KWT","KGZ","LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","MAC","MKD","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MTQ","MRT","MUS","MYT","MEX","FSM","MDA","MCO","MNG","MNE","MSR","MAR","MOZ","MMR","NAM","NRU","NPL","NLD","NCL","NZL","NIC","NER","NGA","NIU","NFK","MNP","NOR","OMN","PAK","PLW","PSE","PAN","PNG","PRY","PER","PHL","PCN","POL","PRT","PRI","QAT","REU","ROU","RUS","RWA","BLM","SHN","KNA","LCA","MAF","SPM","VCT","WSM","SMR","STP","SAU","SEN","SRB","SYC","SLE","SGP","SXM","SVK","SVN","SLB","SOM","ZAF","SGS","SSD","ESP","LKA","SDN","SUR","SJM","SWZ","SWE","CHE","SYR","TWN","TJK","TZA","THA","TLS","TGO","TKL","TON","TTO","TUN","TUR","TKM","TCA","TUV","UGA","UKR","ARE","GBR","USA","UMI","URY","UZB","VUT","VEN","VNM","VGB","VIR","WLF","ESH","YEM","ZMB","ZWE"];var Ct=/[^A-Z0-9+\/=]/i;var Nt=/^[a-z]+\/[a-z0-9\-\+]+$/i,Tt=/^[a-z\-]+=[a-z0-9\-]+$/i,xt=/^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;var Bt=/^magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32,40}&dn=.+&tr=.+$/i;var wt=/^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i,Gt=/^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i,Dt=/^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i;var Ot=/^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/,Ut=/^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/,yt=/^\d{4}$/,Pt=/^\d{5}$/,bt=/^\d{6}$/,Kt={AD:/^AD\d{3}$/,AT:yt,AU:yt,BE:yt,BG:yt,CA:/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,CH:yt,CZ:/^\d{3}\s?\d{2}$/,DE:Pt,DK:yt,DZ:Pt,EE:Pt,ES:Pt,FI:Pt,FR:/^\d{2}\s?\d{3}$/,GB:/^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,GR:/^\d{3}\s?\d{2}$/,HR:/^([1-5]\d{4}$)/,HU:yt,ID:Pt,IL:Pt,IN:bt,IS:/^\d{3}$/,IT:Pt,JP:/^\d{3}\-\d{4}$/,KE:Pt,LI:/^(948[5-9]|949[0-7])$/,LT:/^LT\-\d{5}$/,LU:yt,LV:/^LV\-\d{4}$/,MX:Pt,NL:/^\d{4}\s?[a-z]{2}$/i,NO:yt,PL:/^\d{2}\-\d{3}$/,PT:/^\d{4}\-\d{3}?$/,RO:bt,RU:bt,SA:Pt,SE:/^\d{3}\s?\d{2}$/,SI:yt,SK:/^\d{3}\s?\d{2}$/,TN:yt,TW:/^\d{3}(\d{2})?$/,UA:Pt,US:/^\d{5}(-\d{4})?$/,ZA:yt,ZM:Pt},kt=Object.keys(Kt);function Ht(t,e){$(t);var r=e?new RegExp("^[".concat(e,"]+"),"g"):/^\s+/g;return t.replace(r,"")}function zt(t,e){$(t);for(var r=e?new RegExp("[".concat(e,"]")):/\s/,n=t.length-1;0<=n&&r.test(t[n]);n--);return n]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,n,o,i,a,l,s,u;if(e=p(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:q,isDecimal:function(t,e){if($(t),(e=p(e,Q)).locale in C)return!J(X,t.replace(/ /g,""))&&function(t){return new RegExp("^[-+]?([0-9]+)?(\\".concat(C[t.locale],"[0-9]{").concat(t.decimal_digits,"})").concat(t.force_decimal?"":"?","$"))}(e).test(t);throw new Error("Invalid locale '".concat(e.locale,"'"))},isHexadecimal:et,isDivisibleBy:function(t,e){return $(t),r(t)%parseInt(e,10)==0},isHexColor:function(t){return $(t),rt.test(t)},isISRC:function(t){return $(t),nt.test(t)},isMD5:function(t){return $(t),ot.test(t)},isHash:function(t,e){return $(t),new RegExp("^[a-f0-9]{".concat(it[e],"}$")).test(t)},isJWT:function(t){return $(t),at.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=p(e,lt)).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,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:g,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),Wt(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:Wt,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=p(e,Yt);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,Qt)),!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<=Vt.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<=jt.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<=Jt.indexOf(o[1])){if(e.yahoo_remove_subaddress){var i=o[0].split("-");o[0]=1 Date: Tue, 21 May 2019 14:25:46 +0100 Subject: [PATCH 2/2] correction in isIBAN comment --- src/lib/isIBAN.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isIBAN.js b/src/lib/isIBAN.js index 31d6b18e4..c8a30f341 100644 --- a/src/lib/isIBAN.js +++ b/src/lib/isIBAN.js @@ -76,7 +76,7 @@ const iban = { * @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 10 digit by 97 and add the result to the beginning of the remain IBAN + * 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) => {