From 0b0b4e97aef4dc51616c9767bd936c3f900f25a6 Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Tue, 1 Dec 2020 04:20:18 +0300 Subject: [PATCH 001/113] fix: update v on changelog we recalled 13.5.0 due to build issues #1538 #1537 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 826f6ef83..0dfbeaeab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -#### 13.5.0 +#### ~13.5.0~ 13.5.1 - **New features**: - `isVAT` [#1463](https://github.com/validatorjs/validator.js/pull/1463) @ CodingNagger From 9dc4ed32611075a1a9426d0085c56643b69eb7fc Mon Sep 17 00:00:00 2001 From: Shah Nawaz Awan Date: Wed, 2 Dec 2020 01:16:15 +0500 Subject: [PATCH 002/113] feat(isMobilePhone): add ar-OM locale (#1506) --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 19 +++++++++++++++++++ validator.js | 3 ++- validator.min.js | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fd00e458e..5a414daef 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-MA', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-CA', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-MA', 'ar-OM', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-CA', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 119a4c14c..acfd501d5 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -13,6 +13,7 @@ const phones = { 'ar-KW': /^(\+?965)[569]\d{7}$/, 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/, 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/, + 'ar-OM': /^((\+|00)968)?(9[1-9])\d{6}$/, 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/, 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, 'ar-TN': /^(\+?216)?[2459]\d{7}$/, diff --git a/test/validators.js b/test/validators.js index f47d3ac0f..96513fa27 100644 --- a/test/validators.js +++ b/test/validators.js @@ -5361,6 +5361,25 @@ describe('Validators', () => { '00212408186135', ], }, + { + locale: 'ar-OM', + valid: [ + '+96891212121', + '0096899999999', + '93112211', + '99099009', + ], + invalid: [ + '+96890212121', + '0096890999999', + '0090999999', + '+9689021212', + '', + '+212234', + '+21', + '02122333', + ], + }, { locale: 'ar-SY', valid: [ diff --git a/validator.js b/validator.js index 662c73ce0..4fa15bd85 100644 --- a/validator.js +++ b/validator.js @@ -3768,6 +3768,7 @@ var phones = { 'ar-KW': /^(\+?965)[569]\d{7}$/, 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/, 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/, + 'ar-OM': /^((\+|00)968)?(9[1-9])\d{6}$/, 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/, 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, 'ar-TN': /^(\+?216)?[2459]\d{7}$/, @@ -4619,7 +4620,7 @@ function isVAT(str, countryCode) { throw new Error("Invalid country code: '".concat(countryCode, "'")); } -var version = '13.5.0'; +var version = '13.5.1'; var validator = { version: version, toDate: toDate, diff --git a/validator.min.js b/validator.min.js index d6b3a7682..3c082851b 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 o(t){return(o="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 h(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}(t,e)||u(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||u(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}a["fr-CA"]=a["fr-FR"],s["fr-CA"]=s["fr-FR"],a["pt-BR"]=a["pt-PT"],s["pt-BR"]=s["pt-PT"],c["pt-BR"]=c["pt-PT"],a["pl-Pl"]=a["pl-PL"],s["pl-Pl"]=s["pl-PL"],c["pl-Pl"]=c["pl-PL"],a["fa-AF"]=a.fa;var C=Object.keys(c);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===o(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0o)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(n.shift(),n.shift(),i=!0):"::"===t.substr(t.length-2)&&(n.pop(),n.pop(),i=!0);for(var s=0;s$/i,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(s)throw a}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&o}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=(pt="i",$t=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"].join(""),new RegExp($t,pt));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var vt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},mt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return g(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){g(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;var n=t.indexOf("=");return-1===n||n===r-1||n===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){g(t);var e={X:0,Y:1,Z:2},r=t.trim().toUpperCase();if(!/^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/.test(r))return!1;var n=r.slice(0,-1).replace(/[X,Y,Z]/g,function(t){return e[t]});return r.endsWith(["T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E"][n%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],e=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(e))return!1;var i=0;return e.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(i.getFullYear()===e&&i.getMonth()===r-1&&i.getDate()===n)}function o(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(s[n],10);return c[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],s=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],c=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=i(r)))return!1;var n="19".concat(t.substring(6,12));return!!(e=a(n))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=i(r)))return!1;var n=t.substring(6,14);return!!(e=a(n))&&o(t)})(e)},"zh-TW":function(t){var i={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},e=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(e)&&Array.from(e).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);var n=i[e];return n%10*9+Math.floor(n/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(i){var t=10-i.slice(0,-1).split("").map(function(t,e){return Number(t)*(r=i.length,n=e,r===Ht?n%2==0?3:1:n%2==0?1:3);var r,n}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(o-1).concat(r):"".concat(o).concat(r);else if(r="".concat(o-1).concat(r),a-parseInt(r,10)<100)return!1}60?,.\/ ]$/,rr={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function nr(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){qe.test(t)?i.uppercaseCount+=n[t]:Qe.test(t)?i.lowercaseCount+=n[t]:tr.test(t)?i.numberCount+=n[t]:er.test(t)&&(i.symbolCount+=n[t])}),i}var ir={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/};return{version:"13.5.0",toDate:i,toFloat:F,toInt:function(t,e){return g(t),parseInt(t,e||10)},toBoolean:function(t,e){return g(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return g(t),t===e},contains:function(t,e,r){return g(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return g(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(g(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=h(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i),r=e?e[1]:t;if(r.trim()){if(/[\.";<>]/.test(r)){if(!e)return;if(!(r.split('"').length===r.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a,o,s,c,l=t.split("#");if(1<(l=(t=(l=(t=l.shift()).split("?")).shift()).split("://")).length){if(r=l.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;l[0]=t.substr(2)}}if(""===(t=l.join("://")))return!1;if(""===(t=(l=t.split("/")).shift())&&!e.require_host)return!0;if(1<(l=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(n=l.shift()).indexOf(":")||0<=n.indexOf(":")&&2/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),He(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:He,isWhitelisted:function(t,e){g(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Ke);var r,n=t.split("@"),i=n.pop(),a=[n.join("@"),i];if(a[1]=a[1].toLowerCase(),"gmail.com"===a[1]||"googlemail.com"===a[1]){if(e.gmail_remove_subaddress&&(a[0]=a[0].split("+")[0]),e.gmail_remove_dots&&(a[0]=a[0].replace(/\.+/g,Je)),!a[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(a[0]=a[0].toLowerCase()),a[1]=e.gmail_convert_googlemaildotcom?"gmail.com":a[1]}else if(0<=Ve.indexOf(a[1])){if(e.icloud_remove_subaddress&&(a[0]=a[0].split("+")[0]),!a[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(a[0]=a[0].toLowerCase())}else if(0<=We.indexOf(a[1])){if(e.outlookdotcom_remove_subaddress&&(a[0]=a[0].split("+")[0]),!a[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(a[0]=a[0].toLowerCase())}else if(0<=ze.indexOf(a[1])){if(e.yahoo_remove_subaddress&&(r=a[0].split("-"),a[0]=1=e.minLength&&a.lowercaseCount>=e.minLowercase&&a.uppercaseCount>=e.minUppercase&&a.numberCount>=e.minNumbers&&a.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,We={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function ze(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){ke.test(t)?i.uppercaseCount+=n[t]:He.test(t)?i.lowercaseCount+=n[t]:Ke.test(t)?i.numberCount+=n[t]:Ve.test(t)&&(i.symbolCount+=n[t])}),i}var je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),ye(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:ye,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Be);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Oe)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=Ue.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=xe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1 Date: Wed, 2 Dec 2020 07:48:55 +0100 Subject: [PATCH 003/113] feat(isVAT): add IT locale (#1536) * feat(isVAT): add Italian regex * test(isVAT): add Italian regex testing --- README.md | 2 +- src/lib/isVAT.js | 1 + test/validators.js | 16 ++++++++++++++++ validator.js | 3 ++- validator.min.js | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a414daef..3cdc4d37a 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ Validator | Description **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 }`.

require_protocol - if set as true isURL will return false if protocol is not present in the URL.
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
protocols - valid protocols can be modified with this option.
require_host - if set as false isURL will not check if host is present in the URL.
require_port - if set as true isURL will check if port is present in the URL.
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.
validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). **isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). **isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. -**isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

Available country codes: `[ 'GB' ]`. +**isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

Available country codes: `[ 'GB', 'IT' ]`. **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')`. diff --git a/src/lib/isVAT.js b/src/lib/isVAT.js index 49084f191..549bf336f 100644 --- a/src/lib/isVAT.js +++ b/src/lib/isVAT.js @@ -2,6 +2,7 @@ import assertString from './util/assertString'; export const vatMatchers = { GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/, + IT: /^(IT)?[0-9]{11}$/, }; export default function isVAT(str, countryCode) { diff --git a/test/validators.js b/test/validators.js index 96513fa27..c274fc52f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10216,6 +10216,22 @@ describe('Validators', () => { ], }); + test({ + validator: 'isVAT', + args: ['IT'], + valid: [ + 'IT12345678910', + '12345678910', + ], + invalid: [ + 'IT12345678 910', + 'IT 123456789101', + 'IT123456789101', + 'GB12345678910', + 'IT123456789', + ], + }); + test({ validator: 'isVAT', args: ['invalidCountryCode'], diff --git a/validator.js b/validator.js index 4fa15bd85..ecae1f18b 100644 --- a/validator.js +++ b/validator.js @@ -4607,7 +4607,8 @@ function isStrongPassword(str) { } var vatMatchers = { - GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/ + GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/, + IT: /^(IT)?[0-9]{11}$/ }; function isVAT(str, countryCode) { assertString(str); diff --git a/validator.min.js b/validator.min.js index 3c082851b..ac9977ff7 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 i(t){return(i="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 u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}(t,e)||c(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,We={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function ze(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){ke.test(t)?i.uppercaseCount+=n[t]:He.test(t)?i.lowercaseCount+=n[t]:Ke.test(t)?i.numberCount+=n[t]:Ve.test(t)&&(i.symbolCount+=n[t])}),i}var je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),ye(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:ye,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Be);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Oe)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=Ue.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=xe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,We={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function ze(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){ke.test(t)?i.uppercaseCount+=n[t]:He.test(t)?i.lowercaseCount+=n[t]:Ke.test(t)?i.numberCount+=n[t]:Ve.test(t)&&(i.symbolCount+=n[t])}),i}var je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),ye(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:ye,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Be);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Oe)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=Ue.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=xe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1 Date: Thu, 3 Dec 2020 06:44:17 +0300 Subject: [PATCH 004/113] fix(isMobilePhone): update es-CO locale (#1541) --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 3 ++- validator.js | 2 +- validator.min.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index acfd501d5..452cb97b0 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -56,7 +56,7 @@ const phones = { 'en-ZW': /^(\+263)[0-9]{9}$/, 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/, 'es-BO': /^(\+?591)?(6|7)\d{7}$/, - 'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[2-9]{1}\d{6}$/, + 'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[0-9]{1}\d{6}$/, 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/, 'es-CR': /^(\+506)?[2-8]\d{7}$/, 'es-DO': /^(\+?1)?8[024]9\d{7}$/, diff --git a/test/validators.js b/test/validators.js index c274fc52f..0a02504f9 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6436,6 +6436,8 @@ describe('Validators', () => { '5784321235', '5784321235', '9821235', + '573011140876', + '0698345', ], invalid: [ '1234', @@ -6447,7 +6449,6 @@ describe('Validators', () => { '5714003425432', '5703013347567', '069834567', - '0698345', '969834567', ], }, diff --git a/validator.js b/validator.js index ecae1f18b..2453e5560 100644 --- a/validator.js +++ b/validator.js @@ -3811,7 +3811,7 @@ var phones = { 'en-ZW': /^(\+263)[0-9]{9}$/, 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/, 'es-BO': /^(\+?591)?(6|7)\d{7}$/, - 'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[2-9]{1}\d{6}$/, + 'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[0-9]{1}\d{6}$/, 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/, 'es-CR': /^(\+506)?[2-8]\d{7}$/, 'es-DO': /^(\+?1)?8[024]9\d{7}$/, diff --git a/validator.min.js b/validator.min.js index ac9977ff7..6357e55ee 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 i(t){return(i="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 u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}(t,e)||c(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,We={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function ze(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){ke.test(t)?i.uppercaseCount+=n[t]:He.test(t)?i.lowercaseCount+=n[t]:Ke.test(t)?i.numberCount+=n[t]:Ve.test(t)&&(i.symbolCount+=n[t])}),i}var je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),ye(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:ye,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Be);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Oe)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=Ue.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=xe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,We={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function ze(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){ke.test(t)?i.uppercaseCount+=n[t]:He.test(t)?i.lowercaseCount+=n[t]:Ke.test(t)?i.numberCount+=n[t]:Ve.test(t)&&(i.symbolCount+=n[t])}),i}var je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),ye(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:ye,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Be);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Oe)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=Ue.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=xe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1 Date: Tue, 8 Dec 2020 21:21:33 +0100 Subject: [PATCH 005/113] feat(isMobilePhone): add pt-AO locale (#1505) * feat Add support for Angola mobile phone numbers * feat: update readme --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3cdc4d37a..1f6c4d92f 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-MA', 'ar-OM', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-CA', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 452cb97b0..b8e4452ac 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -98,6 +98,7 @@ const phones = { 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/, 'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[2-9]{1}\d{3}\-?\d{4}))$/, 'pt-PT': /^(\+?351)?9[1236]\d{7}$/, + 'pt-AO': /^(\+244)\d{9}$/, '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})$/, diff --git a/test/validators.js b/test/validators.js index 0a02504f9..bfb53c0e1 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7399,6 +7399,20 @@ describe('Validators', () => { 'NotANumber', ], }, + { + locale: 'pt-AO', + valid: [ + '+244911123432', + '+244123091232', + ], + invalid: [ + '+2449111234321', + '31234', + '31234567', + '512345', + 'NotANumber', + ], + }, ]; let allValid = []; From 3358f45de58727cf47865ec8e32f45175a15d731 Mon Sep 17 00:00:00 2001 From: Sarhan Aissi Date: Tue, 8 Dec 2020 21:25:50 +0100 Subject: [PATCH 006/113] fix(isFQDN): numeric domain names (#1546) fixes #1545 #1543 #1544 --- src/lib/isFQDN.js | 39 ++++++++++++++++++++++++++------------- test/validators.js | 3 +++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/lib/isFQDN.js b/src/lib/isFQDN.js index e58c7503d..3dff7d2fd 100644 --- a/src/lib/isFQDN.js +++ b/src/lib/isFQDN.js @@ -17,39 +17,52 @@ export default function isFQDN(str, options) { str = str.substring(0, str.length - 1); } const parts = str.split('.'); - for (let i = 0; i < parts.length; i++) { - if (parts[i].length > 63) { + const tld = parts[parts.length - 1]; + + if (options.require_tld) { + // disallow fqdns without tld + if (parts.length < 2) { return false; } - } - if (options.require_tld) { - const tld = parts.pop(); - if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) { + + if (!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) { return false; } + // disallow spaces && special characers if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) { return false; } } - for (let part, i = 0; i < parts.length; i++) { - part = parts[i]; - if (!options.allow_numeric_tld && i === parts.length - 1 && /^\d+$/.test(part)) { - return false; // reject numeric TLDs + + // reject numeric TLDs + if (!options.allow_numeric_tld && /^\d+$/.test(tld)) { + return false; + } + + return parts.every((part) => { + if (part.length > 63) { + return false; } + if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) { return false; } + // disallow full-width chars if (/[\uff01-\uff5e]/.test(part)) { return false; } - if (part[0] === '-' || part[part.length - 1] === '-') { + + // disallow parts starting or ending with hyphen + if (/^-|-$/.test(part)) { return false; } + if (!options.allow_underscores && /_/.test(part)) { return false; } - } - return true; + + return true; + }); } diff --git a/test/validators.js b/test/validators.js index bfb53c0e1..4bb00d3f5 100644 --- a/test/validators.js +++ b/test/validators.js @@ -79,6 +79,7 @@ describe('Validators', () => { `${repeat('a', 31)}@gmail.com`, 'test@gmail.com', 'test.1@gmail.com', + 'test@1337.com', ], invalid: [ 'invalidemail@', @@ -374,6 +375,7 @@ describe('Validators', () => { 'http://[2010:836B:4179::836B:4179]', 'http://example.com/example.json#/foo/bar', 'http://user:@www.foobar.com', + 'http://1337.com', ], invalid: [ 'http://localhost:3000/', @@ -894,6 +896,7 @@ describe('Validators', () => { 'foo--bar.com', 'xn--froschgrn-x9a.com', 'rebecca.blackfriday', + '1337.com', ], invalid: [ 'abc', From 787df1971c08050452a64127939c4d9b2dcc273a Mon Sep 17 00:00:00 2001 From: Ezrqn Kemboi Date: Wed, 9 Dec 2020 17:59:02 +0300 Subject: [PATCH 007/113] fix(isBtcAddress): add base58 (#1548) --- src/lib/isBtcAddress.js | 9 +++++++-- test/validators.js | 6 ++++++ validator.js | 15 ++++++++++++--- validator.min.js | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/lib/isBtcAddress.js b/src/lib/isBtcAddress.js index 0c50142a2..2dfd04651 100644 --- a/src/lib/isBtcAddress.js +++ b/src/lib/isBtcAddress.js @@ -1,9 +1,14 @@ import assertString from './util/assertString'; // supports Bech32 addresses -const btc = /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/; +const bech32 = /^(bc1)[a-z0-9]{25,39}$/; +const base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/; export default function isBtcAddress(str) { assertString(str); - return btc.test(str); + // check for bech32 + if (str.startsWith('bc1')) { + return bech32.test(str); + } + return base58.test(str); } diff --git a/test/validators.js b/test/validators.js index 4bb00d3f5..c1e338961 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8470,11 +8470,17 @@ describe('Validators', () => { '1MUz4VMYui5qY1mxUiG8BQ1Luv6tqkvaiL', '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy', 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', + '14qViLJfdGaP4EeHnDyJbEGQysnCpwk3gd', + '35bSzXvRKLpHsHMrzb82f617cV4Srnt7hS', + '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhemt', + 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4', ], invalid: [ '4J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy', '0x56F0B8A998425c53c75C4A303D4eF987533c5597', 'pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g', + '17VZNX1SN5NlKa8UQFxwQbFeFc3iqRYhem', + 'BC1QW508D6QEJXTDG4Y5R3ZARVAYR0C5XW7KV8F3T4', ], }); }); diff --git a/validator.js b/validator.js index 2453e5560..e385bd0aa 100644 --- a/validator.js +++ b/validator.js @@ -4000,10 +4000,19 @@ function isCurrency(str, options) { return currencyRegex(options).test(str); } -var btc = /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/; +var bech32 = /^(bc1)[a-z0-9]{25,39}$/; +var base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/; function isBtcAddress(str) { - assertString(str); - return btc.test(str); + assertString(str); // check for bech32 + + if (str.startsWith('bc1')) { + console.log({ + str: str + }); + return bech32.test(str); + } + + return base58.test(str); } /* eslint-disable max-len */ diff --git a/validator.min.js b/validator.min.js index 6357e55ee..4848de909 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 i(t){return(i="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 u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}(t,e)||c(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,We={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function ze(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){ke.test(t)?i.uppercaseCount+=n[t]:He.test(t)?i.lowercaseCount+=n[t]:Ke.test(t)?i.numberCount+=n[t]:Ve.test(t)&&(i.symbolCount+=n[t])}),i}var je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),ye(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:ye,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Be);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Oe)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=Ue.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=xe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,ze={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function je(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){He.test(t)?i.uppercaseCount+=n[t]:Ke.test(t)?i.lowercaseCount+=n[t]:Ve.test(t)?i.numberCount+=n[t]:We.test(t)&&(i.symbolCount+=n[t])}),i}var Je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),Be(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Be,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Ue);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Ye)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=xe.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Ge.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1 Date: Thu, 17 Dec 2020 09:51:41 +0530 Subject: [PATCH 008/113] feat(isMobilePhone): update de-CH, add fr-CH, it-CH locales (#1554) * fix(isMobilePhone): update de-CH locale (#1549) feat(isMobilePhone): add fr-CH locale (#1549) feat(isMobilePhone): add it-CH locale (#1549) * fix(isMobilePhone): update de-CH, fr-CH and it-CH locale in validator.min.js(#1549) * fix(isMobilePhone): update fr-CH and it-CH locale aliases (#1549) Co-authored-by: Ashutosh Kumar --- src/lib/isMobilePhone.js | 4 +++- test/validators.js | 5 +++-- validator.js | 4 +++- validator.min.js | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index b8e4452ac..c34d45dfb 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -27,7 +27,7 @@ const phones = { 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/, 'de-DE': /^(\+49)?0?[1|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/, 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/, - 'de-CH': /^(\+41|0)(7[5-9])\d{1,7}$/, + 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/, 'de-LU': /^(\+352)?((6\d1)\d{6})$/, 'el-GR': /^(\+?30|0)?(69\d{8})$/, 'en-AU': /^(\+?61|0)4\d{8}$/, @@ -123,6 +123,8 @@ phones['fr-BE'] = phones['nl-BE']; phones['zh-HK'] = phones['en-HK']; phones['zh-MO'] = phones['en-MO']; phones['ga-IE'] = phones['en-IE']; +phones['fr-CH'] = phones['de-CH']; +phones['it-CH'] = phones['fr-CH']; export default function isMobilePhone(str, locale, options) { assertString(str); diff --git a/test/validators.js b/test/validators.js index c1e338961..ca769aea6 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7487,7 +7487,7 @@ describe('Validators', () => { }); }); - // de-CH + // de-CH, fr-CH, it-CH test({ validator: 'isMobilePhone', valid: [ @@ -7496,9 +7496,10 @@ describe('Validators', () => { '+41771112233', '+41781112233', '+41791112233', + '+411122112211', ], invalid: [ - '+41441112233', + '+41041112233', ], args: [], }); diff --git a/validator.js b/validator.js index e385bd0aa..17f28a254 100644 --- a/validator.js +++ b/validator.js @@ -3782,7 +3782,7 @@ var phones = { 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/, 'de-DE': /^(\+49)?0?[1|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/, 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/, - 'de-CH': /^(\+41|0)(7[5-9])\d{1,7}$/, + 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/, 'de-LU': /^(\+352)?((6\d1)\d{6})$/, 'el-GR': /^(\+?30|0)?(69\d{8})$/, 'en-AU': /^(\+?61|0)4\d{8}$/, @@ -3877,6 +3877,8 @@ phones['fr-BE'] = phones['nl-BE']; phones['zh-HK'] = phones['en-HK']; phones['zh-MO'] = phones['en-MO']; phones['ga-IE'] = phones['en-IE']; +phones['fr-CH'] = phones['de-CH']; +phones['it-CH'] = phones['fr-CH']; function isMobilePhone(str, locale, options) { assertString(str); diff --git a/validator.min.js b/validator.min.js index 4848de909..bd24e2c4a 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 i(t){return(i="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 u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}(t,e)||c(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,ze={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function je(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){He.test(t)?i.uppercaseCount+=n[t]:Ke.test(t)?i.lowercaseCount+=n[t]:Ve.test(t)?i.numberCount+=n[t]:We.test(t)&&(i.symbolCount+=n[t])}),i}var Je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),Be(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Be,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Ue);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Ye)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=xe.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Ge.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,ze={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function je(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){He.test(t)?i.uppercaseCount+=n[t]:Ke.test(t)?i.lowercaseCount+=n[t]:Ve.test(t)?i.numberCount+=n[t]:We.test(t)&&(i.symbolCount+=n[t])}),i}var Je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),Be(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Be,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Ue);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Ye)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=xe.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Ge.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1 Date: Thu, 17 Dec 2020 11:02:24 +0100 Subject: [PATCH 009/113] =?UTF-8?q?feat(isLicensePlate):=20new=20validator?= =?UTF-8?q?=20=F0=9F=8E=89=20(#1495)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added isLicensePlate check with german locale * de-LI (Liechtenstein) validator * Added albanian number plates * reversed changes in index.js * reversed changes in index.js * Refactored de-DE into one big regex, expanded tests fot de-DE * added pt-PT locale * Fixed coverage problem * feat(isLicensePlate): clean build * coverage is now 100% * Update README.md * Update README.md --- README.md | 1 + index.js | 305 ++++++++++++++++++++++++++++++++++++++ src/index.js | 2 + src/lib/isLicensePlate.js | 29 ++++ test/validators.js | 106 ++++++++++++- validator.js | 75 +++++++--- validator.min.js | 3 +- 7 files changed, 500 insertions(+), 21 deletions(-) create mode 100644 index.js create mode 100644 src/lib/isLicensePlate.js diff --git a/README.md b/README.md index 1f6c4d92f..b2896b73f 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ Validator | Description **isJWT(str)** | check if the string is valid JWT token. **isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.

`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format. **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. +**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL']` or `any`) **isLocale(str)** | check if the string is a locale **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. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. diff --git a/index.js b/index.js new file mode 100644 index 000000000..c45f62ef4 --- /dev/null +++ b/index.js @@ -0,0 +1,305 @@ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; + +var _toDate = _interopRequireDefault(require("./lib/toDate")); + +var _toFloat = _interopRequireDefault(require("./lib/toFloat")); + +var _toInt = _interopRequireDefault(require("./lib/toInt")); + +var _toBoolean = _interopRequireDefault(require("./lib/toBoolean")); + +var _equals = _interopRequireDefault(require("./lib/equals")); + +var _contains = _interopRequireDefault(require("./lib/contains")); + +var _matches = _interopRequireDefault(require("./lib/matches")); + +var _isEmail = _interopRequireDefault(require("./lib/isEmail")); + +var _isURL = _interopRequireDefault(require("./lib/isURL")); + +var _isMACAddress = _interopRequireDefault(require("./lib/isMACAddress")); + +var _isIP = _interopRequireDefault(require("./lib/isIP")); + +var _isIPRange = _interopRequireDefault(require("./lib/isIPRange")); + +var _isFQDN = _interopRequireDefault(require("./lib/isFQDN")); + +var _isDate = _interopRequireDefault(require("./lib/isDate")); + +var _isBoolean = _interopRequireDefault(require("./lib/isBoolean")); + +var _isLocale = _interopRequireDefault(require("./lib/isLocale")); + +var _isAlpha = _interopRequireWildcard(require("./lib/isAlpha")); + +var _isAlphanumeric = _interopRequireWildcard(require("./lib/isAlphanumeric")); + +var _isNumeric = _interopRequireDefault(require("./lib/isNumeric")); + +var _isPassportNumber = _interopRequireDefault(require("./lib/isPassportNumber")); + +var _isPort = _interopRequireDefault(require("./lib/isPort")); + +var _isLowercase = _interopRequireDefault(require("./lib/isLowercase")); + +var _isUppercase = _interopRequireDefault(require("./lib/isUppercase")); + +var _isIMEI = _interopRequireDefault(require("./lib/isIMEI")); + +var _isAscii = _interopRequireDefault(require("./lib/isAscii")); + +var _isFullWidth = _interopRequireDefault(require("./lib/isFullWidth")); + +var _isHalfWidth = _interopRequireDefault(require("./lib/isHalfWidth")); + +var _isVariableWidth = _interopRequireDefault(require("./lib/isVariableWidth")); + +var _isMultibyte = _interopRequireDefault(require("./lib/isMultibyte")); + +var _isSemVer = _interopRequireDefault(require("./lib/isSemVer")); + +var _isSurrogatePair = _interopRequireDefault(require("./lib/isSurrogatePair")); + +var _isInt = _interopRequireDefault(require("./lib/isInt")); + +var _isFloat = _interopRequireWildcard(require("./lib/isFloat")); + +var _isDecimal = _interopRequireDefault(require("./lib/isDecimal")); + +var _isHexadecimal = _interopRequireDefault(require("./lib/isHexadecimal")); + +var _isOctal = _interopRequireDefault(require("./lib/isOctal")); + +var _isDivisibleBy = _interopRequireDefault(require("./lib/isDivisibleBy")); + +var _isHexColor = _interopRequireDefault(require("./lib/isHexColor")); + +var _isRgbColor = _interopRequireDefault(require("./lib/isRgbColor")); + +var _isHSL = _interopRequireDefault(require("./lib/isHSL")); + +var _isISRC = _interopRequireDefault(require("./lib/isISRC")); + +var _isIBAN = _interopRequireDefault(require("./lib/isIBAN")); + +var _isBIC = _interopRequireDefault(require("./lib/isBIC")); + +var _isMD = _interopRequireDefault(require("./lib/isMD5")); + +var _isHash = _interopRequireDefault(require("./lib/isHash")); + +var _isJWT = _interopRequireDefault(require("./lib/isJWT")); + +var _isJSON = _interopRequireDefault(require("./lib/isJSON")); + +var _isEmpty = _interopRequireDefault(require("./lib/isEmpty")); + +var _isLength = _interopRequireDefault(require("./lib/isLength")); + +var _isByteLength = _interopRequireDefault(require("./lib/isByteLength")); + +var _isUUID = _interopRequireDefault(require("./lib/isUUID")); + +var _isMongoId = _interopRequireDefault(require("./lib/isMongoId")); + +var _isAfter = _interopRequireDefault(require("./lib/isAfter")); + +var _isBefore = _interopRequireDefault(require("./lib/isBefore")); + +var _isIn = _interopRequireDefault(require("./lib/isIn")); + +var _isCreditCard = _interopRequireDefault(require("./lib/isCreditCard")); + +var _isIdentityCard = _interopRequireDefault(require("./lib/isIdentityCard")); + +var _isEAN = _interopRequireDefault(require("./lib/isEAN")); + +var _isISIN = _interopRequireDefault(require("./lib/isISIN")); + +var _isISBN = _interopRequireDefault(require("./lib/isISBN")); + +var _isISSN = _interopRequireDefault(require("./lib/isISSN")); + +var _isTaxID = _interopRequireDefault(require("./lib/isTaxID")); + +var _isMobilePhone = _interopRequireWildcard(require("./lib/isMobilePhone")); + +var _isEthereumAddress = _interopRequireDefault(require("./lib/isEthereumAddress")); + +var _isCurrency = _interopRequireDefault(require("./lib/isCurrency")); + +var _isBtcAddress = _interopRequireDefault(require("./lib/isBtcAddress")); + +var _isISO = _interopRequireDefault(require("./lib/isISO8601")); + +var _isRFC = _interopRequireDefault(require("./lib/isRFC3339")); + +var _isISO31661Alpha = _interopRequireDefault(require("./lib/isISO31661Alpha2")); + +var _isISO31661Alpha2 = _interopRequireDefault(require("./lib/isISO31661Alpha3")); + +var _isBase = _interopRequireDefault(require("./lib/isBase32")); + +var _isBase2 = _interopRequireDefault(require("./lib/isBase58")); + +var _isBase3 = _interopRequireDefault(require("./lib/isBase64")); + +var _isDataURI = _interopRequireDefault(require("./lib/isDataURI")); + +var _isMagnetURI = _interopRequireDefault(require("./lib/isMagnetURI")); + +var _isMimeType = _interopRequireDefault(require("./lib/isMimeType")); + +var _isLatLong = _interopRequireDefault(require("./lib/isLatLong")); + +var _isPostalCode = _interopRequireWildcard(require("./lib/isPostalCode")); + +var _ltrim = _interopRequireDefault(require("./lib/ltrim")); + +var _rtrim = _interopRequireDefault(require("./lib/rtrim")); + +var _trim = _interopRequireDefault(require("./lib/trim")); + +var _escape = _interopRequireDefault(require("./lib/escape")); + +var _unescape = _interopRequireDefault(require("./lib/unescape")); + +var _stripLow = _interopRequireDefault(require("./lib/stripLow")); + +var _whitelist = _interopRequireDefault(require("./lib/whitelist")); + +var _blacklist = _interopRequireDefault(require("./lib/blacklist")); + +var _isWhitelisted = _interopRequireDefault(require("./lib/isWhitelisted")); + +var _normalizeEmail = _interopRequireDefault(require("./lib/normalizeEmail")); + +var _isSlug = _interopRequireDefault(require("./lib/isSlug")); + +var _isLicensePlate = _interopRequireDefault(require("./lib/isLicensePlate")); + +var _isStrongPassword = _interopRequireDefault(require("./lib/isStrongPassword")); + +var _isVAT = _interopRequireDefault(require("./lib/isVAT")); + +function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var version = '13.5.1'; +var validator = { + version: version, + toDate: _toDate.default, + toFloat: _toFloat.default, + toInt: _toInt.default, + toBoolean: _toBoolean.default, + equals: _equals.default, + contains: _contains.default, + matches: _matches.default, + isEmail: _isEmail.default, + isURL: _isURL.default, + isMACAddress: _isMACAddress.default, + isIP: _isIP.default, + isIPRange: _isIPRange.default, + isFQDN: _isFQDN.default, + isBoolean: _isBoolean.default, + isIBAN: _isIBAN.default, + isBIC: _isBIC.default, + isAlpha: _isAlpha.default, + isAlphaLocales: _isAlpha.locales, + isAlphanumeric: _isAlphanumeric.default, + isAlphanumericLocales: _isAlphanumeric.locales, + isNumeric: _isNumeric.default, + isPassportNumber: _isPassportNumber.default, + isPort: _isPort.default, + isLowercase: _isLowercase.default, + isUppercase: _isUppercase.default, + isAscii: _isAscii.default, + isFullWidth: _isFullWidth.default, + isHalfWidth: _isHalfWidth.default, + isVariableWidth: _isVariableWidth.default, + isMultibyte: _isMultibyte.default, + isSemVer: _isSemVer.default, + isSurrogatePair: _isSurrogatePair.default, + isInt: _isInt.default, + isIMEI: _isIMEI.default, + isFloat: _isFloat.default, + isFloatLocales: _isFloat.locales, + isDecimal: _isDecimal.default, + isHexadecimal: _isHexadecimal.default, + isOctal: _isOctal.default, + isDivisibleBy: _isDivisibleBy.default, + isHexColor: _isHexColor.default, + isRgbColor: _isRgbColor.default, + isHSL: _isHSL.default, + isISRC: _isISRC.default, + isMD5: _isMD.default, + isHash: _isHash.default, + isJWT: _isJWT.default, + isJSON: _isJSON.default, + isEmpty: _isEmpty.default, + isLength: _isLength.default, + isLocale: _isLocale.default, + isByteLength: _isByteLength.default, + isUUID: _isUUID.default, + isMongoId: _isMongoId.default, + isAfter: _isAfter.default, + isBefore: _isBefore.default, + isIn: _isIn.default, + isCreditCard: _isCreditCard.default, + isIdentityCard: _isIdentityCard.default, + isEAN: _isEAN.default, + isISIN: _isISIN.default, + isISBN: _isISBN.default, + isISSN: _isISSN.default, + isMobilePhone: _isMobilePhone.default, + isMobilePhoneLocales: _isMobilePhone.locales, + isPostalCode: _isPostalCode.default, + isPostalCodeLocales: _isPostalCode.locales, + isEthereumAddress: _isEthereumAddress.default, + isCurrency: _isCurrency.default, + isBtcAddress: _isBtcAddress.default, + isISO8601: _isISO.default, + isRFC3339: _isRFC.default, + isISO31661Alpha2: _isISO31661Alpha.default, + isISO31661Alpha3: _isISO31661Alpha2.default, + isBase32: _isBase.default, + isBase58: _isBase2.default, + isBase64: _isBase3.default, + isDataURI: _isDataURI.default, + isMagnetURI: _isMagnetURI.default, + isMimeType: _isMimeType.default, + isLatLong: _isLatLong.default, + ltrim: _ltrim.default, + rtrim: _rtrim.default, + trim: _trim.default, + escape: _escape.default, + unescape: _unescape.default, + stripLow: _stripLow.default, + whitelist: _whitelist.default, + blacklist: _blacklist.default, + isWhitelisted: _isWhitelisted.default, + normalizeEmail: _normalizeEmail.default, + toString: toString, + isSlug: _isSlug.default, + isStrongPassword: _isStrongPassword.default, + isTaxID: _isTaxID.default, + isDate: _isDate.default, + isLicensePlate: _isLicensePlate.default, + isVAT: _isVAT.default +}; +var _default = validator; +exports.default = _default; +module.exports = exports.default; +module.exports.default = exports.default; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 15b7771b8..e91c582da 100644 --- a/src/index.js +++ b/src/index.js @@ -115,6 +115,7 @@ import isWhitelisted from './lib/isWhitelisted'; import normalizeEmail from './lib/normalizeEmail'; import isSlug from './lib/isSlug'; +import isLicensePlate from './lib/isLicensePlate'; import isStrongPassword from './lib/isStrongPassword'; import isVAT from './lib/isVAT'; @@ -219,6 +220,7 @@ const validator = { isStrongPassword, isTaxID, isDate, + isLicensePlate, isVAT, }; diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js new file mode 100644 index 000000000..c4b010d48 --- /dev/null +++ b/src/lib/isLicensePlate.js @@ -0,0 +1,29 @@ +import assertString from './util/assertString'; + +const validators = { + 'de-DE': str => + /^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS|TR|TÜ|UM|PZ|TP|UE|UN|UH|MN|KK|VB|V|AE|PL|RC|VG|GW|PW|VR|VK|KB|WA|WT|BE|WM|WE|AP|MO|WW|FB|WZ|WI|WB|JE|WF|WO|W|WÜ|BL|Z|GC)[- ]?[A-Z]{1,2}[- ]?\d{1,4}|(AIC|FDB|ABG|SLN|SAW|KLZ|BUL|ESB|NAB|SUL|WST|ABI|AZE|BTF|KÖT|DKB|FEU|ROT|ALZ|SMÜ|WER|AUR|NOR|DÜW|BRK|HAB|TÖL|WOR|BAD|BAR|BER|BIW|EBS|KEM|MÜB|PEG|BGL|BGD|REI|WIL|BKS|BIR|WAT|BOR|BOH|BOT|BRB|BLK|HHM|NEB|NMB|WSF|LEO|HDL|WMS|WZL|BÜS|CHA|KÖZ|ROD|WÜM|CLP|NEC|COC|ZEL|COE|CUX|DAH|LDS|DEG|DEL|RSL|DLG|DGF|LAN|HEI|MED|DON|KIB|ROK|JÜL|MON|SLE|EBE|EIC|HIG|WBS|BIT|PRÜ|LIB|EMD|WIT|ERH|HÖS|ERZ|ANA|ASZ|MAB|MEK|STL|SZB|FDS|HCH|HOR|WOL|FRG|GRA|WOS|FRI|FFB|GAP|GER|BRL|CLZ|GTH|NOH|HGW|GRZ|LÖB|NOL|WSW|DUD|HMÜ|OHA|KRU|HAL|HAM|HBS|QLB|HVL|NAU|HAS|EBN|GEO|HOH|HDH|ERK|HER|WAN|HEF|ROF|HBN|ALF|HSK|USI|NAI|REH|SAN|KÜN|ÖHR|HOL|WAR|ARN|BRG|GNT|HOG|WOH|KEH|MAI|PAR|RID|ROL|KLE|GEL|KUS|KYF|ART|SDH|LDK|DIL|MAL|VIB|LER|BNA|GHA|GRM|MTL|WUR|LEV|LIF|STE|WEL|LIP|VAI|LUP|HGN|LBZ|LWL|PCH|STB|DAN|MKK|SLÜ|MSP|TBB|MGH|MTK|BIN|MSH|EIL|HET|SGH|BID|MYK|MSE|MST|MÜR|WRN|MEI|GRH|RIE|MZG|MIL|OBB|BED|FLÖ|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str), + 'de-LI': str => /^FL[- ]?\d{1,5}[UZ]?$/.test(str), + 'pt-PT': str => + /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str), + 'sq-AL': str => + /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str), +}; + +export default function isLicensePlate(str, locale) { + assertString(str); + if (locale in validators) { + return validators[locale](str); + } else if (locale === 'any') { + for (const key in validators) { + if (validators.hasOwnProperty(key)) { + const validator = validators[key]; + if (validator(str)) { + return true; + } + } + } + return false; + } + throw new Error(`Invalid locale '${locale}'`); +} diff --git a/test/validators.js b/test/validators.js index ca769aea6..93800b474 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10209,7 +10209,111 @@ describe('Validators', () => { ], }); }); - + it('should be valid license plate', () => { + test({ + validator: 'isLicensePlate', + args: ['pt-PT'], + valid: [ + 'AA-12-34', + '12·34·AB', + '12·AB·34', + 'AB 12 CD', + 'AB12CD', + ], + invalid: [ + '', + 'notalicenseplate', + 'A1-B2-C3', + 'ABC-1-EF', + ], + }); + test({ + validator: 'isLicensePlate', + args: ['de-LI'], + valid: [ + 'FL 1', + 'FL 99999', + 'FL 1337', + ], + invalid: [ + '', + 'FL 999999', + 'AB 12345', + 'FL -1', + ], + }); + test({ + validator: 'isLicensePlate', + args: ['de-DE'], + valid: [ + 'M A 1', + 'M A 12', + 'M A 123', + 'M A 1234', + 'M AB 1', + 'M AB 12', + 'M AB 123', + 'M AB 1234', + 'FS A 1', + 'FS A 12', + 'FS A 123', + 'FS A 1234', + 'FS AB 1', + 'FS AB 12', + 'FS AB 123', + 'FS AB 1234', + 'FSAB1234', + 'FS-AB-1234', + 'FS AB 1234 H', + 'FS AB 1234 E', + 'FSAB1234E', + 'FS-AB-1234-E', + ], + invalid: [ + 'YY AB 123', + 'PAF AB 1234', + 'M ABC 123', + 'M AB 12345', + 'FS AB 1234 A', + ], + }); + test({ + validator: 'isLicensePlate', + args: ['sq-AL'], + valid: [ + 'AA 000 AA', + 'ZZ 999 ZZ', + ], + invalid: [ + '', + 'AA 0 A', + 'AAA 00 AAA', + ], + }); + test({ + validator: 'isLicensePlate', + args: ['any'], + valid: [ + 'FL 1', + 'FS AB 123', + ], + invalid: [ + '', + 'FL 999999', + 'FS AB 1234 A', + ], + }); + test({ + validator: 'isLicensePlate', + args: ['asdfasdf'], + error: [ + 'FL 1', + 'FS AB 123', + 'FL 999999', + 'FS AB 1234 A', + ], + }); + }); it('should validate english VAT numbers', () => { test({ validator: 'isVAT', diff --git a/validator.js b/validator.js index 17f28a254..1c9653842 100644 --- a/validator.js +++ b/validator.js @@ -430,17 +430,15 @@ function isFQDN(str, options) { } var parts = str.split('.'); + var tld = parts[parts.length - 1]; - for (var i = 0; i < parts.length; i++) { - if (parts[i].length > 63) { + if (options.require_tld) { + // disallow fqdns without tld + if (parts.length < 2) { return false; } - } - if (options.require_tld) { - var tld = parts.pop(); - - if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) { + if (!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) { return false; } // disallow spaces && special characers @@ -448,13 +446,16 @@ function isFQDN(str, options) { if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) { return false; } - } + } // reject numeric TLDs - for (var part, _i = 0; _i < parts.length; _i++) { - part = parts[_i]; - if (!options.allow_numeric_tld && _i === parts.length - 1 && /^\d+$/.test(part)) { - return false; // reject numeric TLDs + if (!options.allow_numeric_tld && /^\d+$/.test(tld)) { + return false; + } + + return parts.every(function (part) { + if (part.length > 63) { + return false; } if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) { @@ -464,18 +465,19 @@ function isFQDN(str, options) { if (/[\uff01-\uff5e]/.test(part)) { return false; - } + } // disallow parts starting or ending with hyphen - if (part[0] === '-' || part[part.length - 1] === '-') { + + if (/^-|-$/.test(part)) { return false; } if (!options.allow_underscores && /_/.test(part)) { return false; } - } - return true; + return true; + }); } /** @@ -3853,6 +3855,7 @@ var phones = { 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/, 'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[2-9]{1}\d{3}\-?\d{4}))$/, 'pt-PT': /^(\+?351)?9[1236]\d{7}$/, + 'pt-AO': /^(\+244)\d{9}$/, '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})$/, @@ -4008,9 +4011,6 @@ function isBtcAddress(str) { assertString(str); // check for bech32 if (str.startsWith('bc1')) { - console.log({ - str: str - }); return bech32.test(str); } @@ -4518,6 +4518,42 @@ function isSlug(str) { return charsetRegex.test(str); } +var validators$1 = { + 'de-DE': function deDE(str) { + return /^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS|TR|TÜ|UM|PZ|TP|UE|UN|UH|MN|KK|VB|V|AE|PL|RC|VG|GW|PW|VR|VK|KB|WA|WT|BE|WM|WE|AP|MO|WW|FB|WZ|WI|WB|JE|WF|WO|W|WÜ|BL|Z|GC)[- ]?[A-Z]{1,2}[- ]?\d{1,4}|(AIC|FDB|ABG|SLN|SAW|KLZ|BUL|ESB|NAB|SUL|WST|ABI|AZE|BTF|KÖT|DKB|FEU|ROT|ALZ|SMÜ|WER|AUR|NOR|DÜW|BRK|HAB|TÖL|WOR|BAD|BAR|BER|BIW|EBS|KEM|MÜB|PEG|BGL|BGD|REI|WIL|BKS|BIR|WAT|BOR|BOH|BOT|BRB|BLK|HHM|NEB|NMB|WSF|LEO|HDL|WMS|WZL|BÜS|CHA|KÖZ|ROD|WÜM|CLP|NEC|COC|ZEL|COE|CUX|DAH|LDS|DEG|DEL|RSL|DLG|DGF|LAN|HEI|MED|DON|KIB|ROK|JÜL|MON|SLE|EBE|EIC|HIG|WBS|BIT|PRÜ|LIB|EMD|WIT|ERH|HÖS|ERZ|ANA|ASZ|MAB|MEK|STL|SZB|FDS|HCH|HOR|WOL|FRG|GRA|WOS|FRI|FFB|GAP|GER|BRL|CLZ|GTH|NOH|HGW|GRZ|LÖB|NOL|WSW|DUD|HMÜ|OHA|KRU|HAL|HAM|HBS|QLB|HVL|NAU|HAS|EBN|GEO|HOH|HDH|ERK|HER|WAN|HEF|ROF|HBN|ALF|HSK|USI|NAI|REH|SAN|KÜN|ÖHR|HOL|WAR|ARN|BRG|GNT|HOG|WOH|KEH|MAI|PAR|RID|ROL|KLE|GEL|KUS|KYF|ART|SDH|LDK|DIL|MAL|VIB|LER|BNA|GHA|GRM|MTL|WUR|LEV|LIF|STE|WEL|LIP|VAI|LUP|HGN|LBZ|LWL|PCH|STB|DAN|MKK|SLÜ|MSP|TBB|MGH|MTK|BIN|MSH|EIL|HET|SGH|BID|MYK|MSE|MST|MÜR|WRN|MEI|GRH|RIE|MZG|MIL|OBB|BED|FLÖ|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str); + }, + 'de-LI': function deLI(str) { + return /^FL[- ]?\d{1,5}[UZ]?$/.test(str); + }, + 'pt-PT': function ptPT(str) { + return /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str); + }, + 'sq-AL': function sqAL(str) { + return /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str); + } +}; +function isLicensePlate(str, locale) { + assertString(str); + + if (locale in validators$1) { + return validators$1[locale](str); + } else if (locale === 'any') { + for (var key in validators$1) { + if (validators$1.hasOwnProperty(key)) { + var validator = validators$1[key]; + + if (validator(str)) { + return true; + } + } + } + + return false; + } + + throw new Error("Invalid locale '".concat(locale, "'")); +} + var upperCaseRegex = /^[A-Z]$/; var lowerCaseRegex = /^[a-z]$/; var numberRegex = /^[0-9]$/; @@ -4731,6 +4767,7 @@ var validator = { isStrongPassword: isStrongPassword, isTaxID: isTaxID, isDate: isDate, + isLicensePlate: isLicensePlate, isVAT: isVAT }; diff --git a/validator.min.js b/validator.min.js index bd24e2c4a..33d746093 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,5 @@ * 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 i(t){return(i="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 u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}(t,e)||c(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var C=Object.keys(l);function F(t){return E(t)?parseFloat(t):NaN}function _(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function M(t,e){var r,n=0e)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,U=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,P=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,G=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,O=/^([\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 Y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},k=/^\[([^\]]+)\](?::([0-9]+))?$/;function H(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var pt,$t,At=($t="i",pt=(pt=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(pt,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var mt={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},vt=["","-","+"];var It=/^(0x|0h)?[0-9A-F]+$/i;function St(t){return d(t),It.test(t)}var Zt=/^(0o)?[0-7]+$/i;var Et=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Ct=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Ft=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,_t=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Mt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Rt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,bt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Lt=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Nt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Dt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Tt=/^[a-f0-9]{32}$/;var wt={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 yt=/[^A-Z0-9+\/=]/i,Bt=/^[A-Z0-9_\-]*$/i,Ut={urlSafe:!1};function xt(t,e){d(t),e=M(e,Ut);var r=t.length;if(e.urlSafe)return Bt.test(t);if(r%4!=0||yt.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Pt={allow_primitives:!1};var Gt={ignore_whitespace:!1};var Ot={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 Yt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 kt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var Ht=8,Kt=/^(\d{8}|\d{13})$/;function Vt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===Ht?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Wt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,ze={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function je(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){He.test(t)?i.uppercaseCount+=n[t]:Ke.test(t)?i.lowercaseCount+=n[t]:Ve.test(t)?i.numberCount+=n[t]:We.test(t)&&(i.symbolCount+=n[t])}),i}var Je={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:F,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=M(r,R)).ignoreCase?0<=t.toLowerCase().indexOf(_(e).toLowerCase()):0<=t.indexOf(_(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=M(e,y)).require_display_name||e.allow_display_name){var r=t.match(B);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=M(e,Y)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),Be(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Be,isWhitelisted:function(t,e){d(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=M(e,Ue);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Ye)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=xe.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Pe.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Ge.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var R=Object.keys(l);function Z(t){return L(t)?parseFloat(t):NaN}function M(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function B(t,e){var r,n=0e)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,b=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,P=/^[a-z\d]+$/,U=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,w=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,y=/^([\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 K={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},W=/^\[([^\]]+)\](?::([0-9]+))?$/;function x(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var At,$t,pt=($t="i",At=(At=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(At,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var St={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},Et=["","-","+"];var mt=/^(0x|0h)?[0-9A-F]+$/i;function vt(t){return d(t),mt.test(t)}var It=/^(0o)?[0-7]+$/i;var Lt=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Rt=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Zt=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,Mt=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Bt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Ft=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,Nt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Ct=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Dt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Tt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Gt=/^[a-f0-9]{32}$/;var Ot={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 _t=/[^A-Z0-9+\/=]/i,Ht=/^[A-Z0-9_\-]*$/i,bt={urlSafe:!1};function Pt(t,e){d(t),e=B(e,bt);var r=t.length;if(e.urlSafe)return Ht.test(t);if(r%4!=0||_t.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Ut={allow_primitives:!1};var wt={ignore_whitespace:!1};var yt={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 Kt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 Wt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var xt=8,Yt=/^(\d{8}|\d{13})$/;function kt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===xt?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Vt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,je={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function Je(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){Ye.test(t)?i.uppercaseCount+=n[t]:ke.test(t)?i.lowercaseCount+=n[t]:Ve.test(t)?i.numberCount+=n[t]:ze.test(t)&&(i.symbolCount+=n[t])}),i}var Xe={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:Z,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=B(r,F)).ignoreCase?0<=t.toLowerCase().indexOf(M(e).toLowerCase()):0<=t.indexOf(M(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=B(e,_)).require_display_name||e.allow_display_name){var r=t.match(H);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=B(e,K)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),He(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:He,isWhitelisted:function(t,e){d(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=B(e,be);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Ke)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=Pe.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Ue.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=we.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1 Date: Thu, 17 Dec 2020 12:11:58 +0200 Subject: [PATCH 010/113] fix(isTaxID): fix el-GR locale when checksum is 10 (#1529) Add correct tax identifier to demonstrate issue and fix. Thanks to: Panos Papadopoulos --- src/lib/isTaxID.js | 2 +- test/validators.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/isTaxID.js b/src/lib/isTaxID.js index 40edfe381..90a0c2a96 100644 --- a/src/lib/isTaxID.js +++ b/src/lib/isTaxID.js @@ -280,7 +280,7 @@ function elGrCheck(tin) { for (let i = 0; i < 8; i++) { checksum += digits[i] * (2 ** (8 - i)); } - return checksum % 11 === digits[8]; + return ((checksum % 11) % 10) === digits[8]; } /* diff --git a/test/validators.js b/test/validators.js index 93800b474..baeca631a 100644 --- a/test/validators.js +++ b/test/validators.js @@ -9615,6 +9615,7 @@ describe('Validators', () => { args: ['el-GR'], valid: [ '758426713', + '032792320', '054100004'], invalid: [ '054100005', From 1b85829bd6bdf660b2989cdd094bcd80f7d3b975 Mon Sep 17 00:00:00 2001 From: Kyle Dinh Date: Thu, 14 Jan 2021 09:45:48 +0700 Subject: [PATCH 011/113] feat(isMobileNumber): add support new telco numbers for VN locale (#1575) * Support new VN mobile phone 087 (https://didong.itelecom.vn/) * Add test for new telco number Co-authored-by: Kyle Dinh --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index c34d45dfb..68a19922e 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -110,7 +110,7 @@ const phones = { 'tr-TR': /^(\+?90|0)?5\d{9}$/, 'uk-UA': /^(\+?38|8)?0\d{9}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, - 'vi-VN': /^(\+?84|0)((3([2-9]))|(5([2689]))|(7([0|6-9]))|(8([1-6|89]))|(9([0-9])))([0-9]{7})$/, + 'vi-VN': /^(\+?84|0)((3([2-9]))|(5([2689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, 'zh-CN': /^((\+|00)86)?1([3568][0-9]|4[579]|6[67]|7[01235678]|9[012356789])[0-9]{8}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, }; diff --git a/test/validators.js b/test/validators.js index baeca631a..b9899b626 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6391,6 +6391,7 @@ describe('Validators', () => { '0883805866', '0892405867', '+84888696413', + '0878123456', ], invalid: [ '12345', From 9b03daf281560ef34953d0912be1221a439adb1d Mon Sep 17 00:00:00 2001 From: Sting Alleman Date: Mon, 15 Feb 2021 05:20:42 +0100 Subject: [PATCH 012/113] feat(isStrongPassword): add `@` as valid symbol (#1566) --- src/lib/isStrongPassword.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isStrongPassword.js b/src/lib/isStrongPassword.js index 7433703ad..e18a7597b 100644 --- a/src/lib/isStrongPassword.js +++ b/src/lib/isStrongPassword.js @@ -4,7 +4,7 @@ import assertString from './util/assertString'; const upperCaseRegex = /^[A-Z]$/; const lowerCaseRegex = /^[a-z]$/; const numberRegex = /^[0-9]$/; -const symbolRegex = /^[-#!$%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/; +const symbolRegex = /^[-#!$@%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/; const defaultOptions = { minLength: 8, From 941abe1e087477ad39c235ddd371df39c18a0659 Mon Sep 17 00:00:00 2001 From: Sarhan Aissi Date: Fri, 26 Feb 2021 15:45:58 +0100 Subject: [PATCH 013/113] chore: setup github actions (#1606) * chore: prevent git from ignoring src/index.js file * chore: remove unused exclusion from nyc config * chore: replace travis-ci with github actions * chore: fix issue with github workflow config * chore: fix condition for coverage generation and sending * chore: treat node version as int * docs: replace travis with github actions badge * chore: add npm publish github action * chore: remove auto-generated files * chore: improve github actions styles * chore: use correct repo url to prevent unecessary redirect * chore: lint package.json file * chore: add new line at end of file * chore: set a fixed ubuntu version instead of relying on latest --- .github/workflows/ci.yml | 32 + .github/workflows/npm-publish.yml | 24 + .gitignore | 2 +- .nycrc | 4 - .travis.yml | 14 - CHANGELOG.md | 610 ++-- README.md | 13 +- bower.json | 2 +- index.js | 305 -- package.json | 11 +- validator.js | 4776 ----------------------------- validator.min.js | 24 - 12 files changed, 375 insertions(+), 5442 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/npm-publish.yml delete mode 100644 .travis.yml delete mode 100644 index.js delete mode 100644 validator.js delete mode 100644 validator.min.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..588c6f310 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: CI +on: + push: + branches: [master] + pull_request: + branches: [master] +jobs: + test: + runs-on: ubuntu-20.04 + strategy: + matrix: + node-version: [14, 12, 10, 8, 6] + steps: + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2-beta + with: + node-version: ${{ matrix.node-version }} + check-latest: true + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Install Dependencies + run: npm install + - name: Run Tests + run: npm test + - if: matrix.node-version == 14 + name: Generate coverage file + run: npm run test:ci > coverage.lcov + - if: matrix.node-version == 14 + name: Send coverage info to Codecov + uses: codecov/codecov-action@v1 + with: + file: ./coverage.lcov diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 000000000..b4b62f1b9 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,24 @@ +name: NPM Publish +on: + release: + types: [created] +jobs: + publish: + runs-on: ubuntu-20.04 + steps: + - name: Setup Node.js 14 + uses: actions/setup-node@v2-beta + with: + node-version: 14 + check-latest: true + registry-url: https://registry.npmjs.org/ + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Install Dependencies + run: npm install + - name: Run Tests + run: npm test + - name: Publish Package to NPM Registry + run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_SECRET}} diff --git a/.gitignore b/.gitignore index 02f031234..9c8fa47bf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,6 @@ package-lock.json yarn.lock /es /lib +/index.js validator.js validator.min.js -index.js diff --git a/.nycrc b/.nycrc index 27bf7b772..6b79f893c 100644 --- a/.nycrc +++ b/.nycrc @@ -5,9 +5,5 @@ ], "include": [ "src/**/*.js" - ], - "exclude": [ - "validator.js", - "lib/**/*.js" ] } diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 356e06912..000000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: node_js -node_js: - - stable - - 12 - - 11 - - 10 - - 9 - - 8 - - 6 -notifications: - email: false -after_success: - - npm install -g codecov - - npm run test:ci > coverage.lcov && codecov diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dfbeaeab..865459dd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,441 +84,441 @@ #### 13.1.1 - Hotfix for a regex incompatibility in some browsers - ([#1355](https://github.com/chriso/validator.js/pull/1355) + ([#1355](https://github.com/validatorjs/validator.js/pull/1355) #### 13.1.0 - Added an `isIMEI()` validator - ([#1346](https://github.com/chriso/validator.js/pull/1346)) + ([#1346](https://github.com/validatorjs/validator.js/pull/1346)) - Added an `isDate()` validator - ([#1270](https://github.com/chriso/validator.js/pull/1270)) + ([#1270](https://github.com/validatorjs/validator.js/pull/1270)) - Added an `isTaxID()` validator - ([#1336](https://github.com/chriso/validator.js/pull/1336)) + ([#1336](https://github.com/validatorjs/validator.js/pull/1336)) - Added DMS support to `isLatLong()` - ([#1340](https://github.com/chriso/validator.js/pull/1340)) + ([#1340](https://github.com/validatorjs/validator.js/pull/1340)) - Added support for URL-safe base64 validation - ([#1277](https://github.com/chriso/validator.js/pull/1277)) + ([#1277](https://github.com/validatorjs/validator.js/pull/1277)) - Added support for primitives in `isJSON()` - ([#1328](https://github.com/chriso/validator.js/pull/1328)) + ([#1328](https://github.com/validatorjs/validator.js/pull/1328)) - Added support for case-insensitive matching to `contains()` - ([#1334](https://github.com/chriso/validator.js/pull/1334)) + ([#1334](https://github.com/validatorjs/validator.js/pull/1334)) - Support additional cards in `isCreditCard()` - ([#1177](https://github.com/chriso/validator.js/pull/1177)) + ([#1177](https://github.com/validatorjs/validator.js/pull/1177)) - Support additional currencies in `isCurrency()` - ([#1306](https://github.com/chriso/validator.js/pull/1306)) + ([#1306](https://github.com/validatorjs/validator.js/pull/1306)) - Fixed `isFQDN()` handling of certain special chars - ([#1091](https://github.com/chriso/validator.js/pull/1091)) + ([#1091](https://github.com/validatorjs/validator.js/pull/1091)) - Fixed a bug in `isSlug()` - ([#1338](https://github.com/chriso/validator.js/pull/1338)) + ([#1338](https://github.com/validatorjs/validator.js/pull/1338)) - New and improved locales - ([#1112](https://github.com/chriso/validator.js/pull/1112), - [#1167](https://github.com/chriso/validator.js/pull/1167), - [#1198](https://github.com/chriso/validator.js/pull/1198), - [#1199](https://github.com/chriso/validator.js/pull/1199), - [#1273](https://github.com/chriso/validator.js/pull/1273), - [#1279](https://github.com/chriso/validator.js/pull/1279), - [#1281](https://github.com/chriso/validator.js/pull/1281), - [#1293](https://github.com/chriso/validator.js/pull/1293), - [#1294](https://github.com/chriso/validator.js/pull/1294), - [#1311](https://github.com/chriso/validator.js/pull/1311), - [#1312](https://github.com/chriso/validator.js/pull/1312), - [#1313](https://github.com/chriso/validator.js/pull/1313), - [#1314](https://github.com/chriso/validator.js/pull/1314), - [#1315](https://github.com/chriso/validator.js/pull/1315), - [#1317](https://github.com/chriso/validator.js/pull/1317), - [#1322](https://github.com/chriso/validator.js/pull/1322), - [#1324](https://github.com/chriso/validator.js/pull/1324), - [#1330](https://github.com/chriso/validator.js/pull/1330), - [#1337](https://github.com/chriso/validator.js/pull/1337)) + ([#1112](https://github.com/validatorjs/validator.js/pull/1112), + [#1167](https://github.com/validatorjs/validator.js/pull/1167), + [#1198](https://github.com/validatorjs/validator.js/pull/1198), + [#1199](https://github.com/validatorjs/validator.js/pull/1199), + [#1273](https://github.com/validatorjs/validator.js/pull/1273), + [#1279](https://github.com/validatorjs/validator.js/pull/1279), + [#1281](https://github.com/validatorjs/validator.js/pull/1281), + [#1293](https://github.com/validatorjs/validator.js/pull/1293), + [#1294](https://github.com/validatorjs/validator.js/pull/1294), + [#1311](https://github.com/validatorjs/validator.js/pull/1311), + [#1312](https://github.com/validatorjs/validator.js/pull/1312), + [#1313](https://github.com/validatorjs/validator.js/pull/1313), + [#1314](https://github.com/validatorjs/validator.js/pull/1314), + [#1315](https://github.com/validatorjs/validator.js/pull/1315), + [#1317](https://github.com/validatorjs/validator.js/pull/1317), + [#1322](https://github.com/validatorjs/validator.js/pull/1322), + [#1324](https://github.com/validatorjs/validator.js/pull/1324), + [#1330](https://github.com/validatorjs/validator.js/pull/1330), + [#1337](https://github.com/validatorjs/validator.js/pull/1337)) #### 13.0.0 - Added `isEthereumAddress()` validator to validate [Ethereum addresses](https://en.wikipedia.org/wiki/Ethereum#Addresses) - ([#1117](https://github.com/chriso/validator.js/pull/1117)) + ([#1117](https://github.com/validatorjs/validator.js/pull/1117)) - Added `isBtcAddress()` validator to validate [Bitcoin addresses](https://en.bitcoin.it/wiki/Address) - ([#1163](https://github.com/chriso/validator.js/pull/1163)) + ([#1163](https://github.com/validatorjs/validator.js/pull/1163)) - Added `isIBAN()` validator to validate [International Bank Account Numbers](https://en.wikipedia.org/wiki/International_Bank_Account_Number) - ([#1243](https://github.com/chriso/validator.js/pull/1243)) + ([#1243](https://github.com/validatorjs/validator.js/pull/1243)) - Added `isEAN()` validator to validate [International Article Numbers](https://en.wikipedia.org/wiki/International_Article_Number) - ([#1244](https://github.com/chriso/validator.js/pull/1244)) + ([#1244](https://github.com/validatorjs/validator.js/pull/1244)) - Added `isSemVer()` validator to validate [Semantic Version Numbers](https://semver.org) - ([#1246](https://github.com/chriso/validator.js/pull/1246)) + ([#1246](https://github.com/validatorjs/validator.js/pull/1246)) - Added `isPassportNumber()` validator - ([#1250](https://github.com/chriso/validator.js/pull/1250)) + ([#1250](https://github.com/validatorjs/validator.js/pull/1250)) - Added `isRgbColor()` validator - ([#1141](https://github.com/chriso/validator.js/pull/1141)) + ([#1141](https://github.com/validatorjs/validator.js/pull/1141)) - Added `isHSL()` validator - ([#1159](https://github.com/chriso/validator.js/pull/1159)) + ([#1159](https://github.com/validatorjs/validator.js/pull/1159)) - Added `isLocale()` validator - ([#1072](https://github.com/chriso/validator.js/pull/1072)) + ([#1072](https://github.com/validatorjs/validator.js/pull/1072)) - Improved the `isIP()` validator - ([#1211](https://github.com/chriso/validator.js/pull/1211)) + ([#1211](https://github.com/validatorjs/validator.js/pull/1211)) - Improved the `isMACAddress()` validator - ([#1267](https://github.com/chriso/validator.js/pull/1267)) + ([#1267](https://github.com/validatorjs/validator.js/pull/1267)) - New and improved locales - ([#1238](https://github.com/chriso/validator.js/pull/1238), - [#1265](https://github.com/chriso/validator.js/pull/1265)) + ([#1238](https://github.com/validatorjs/validator.js/pull/1238), + [#1265](https://github.com/validatorjs/validator.js/pull/1265)) #### 12.2.0 - Support CSS Colors Level 4 spec - ([#1233](https://github.com/chriso/validator.js/pull/1233)) + ([#1233](https://github.com/validatorjs/validator.js/pull/1233)) - Improve the `toFloat()` sanitizer - ([#1227](https://github.com/chriso/validator.js/pull/1227)) + ([#1227](https://github.com/validatorjs/validator.js/pull/1227)) - New and improved locales - ([#1200](https://github.com/chriso/validator.js/pull/1200), - [#1207](https://github.com/chriso/validator.js/pull/1207), - [#1213](https://github.com/chriso/validator.js/pull/1213), - [#1217](https://github.com/chriso/validator.js/pull/1217), - [#1234](https://github.com/chriso/validator.js/pull/1234)) + ([#1200](https://github.com/validatorjs/validator.js/pull/1200), + [#1207](https://github.com/validatorjs/validator.js/pull/1207), + [#1213](https://github.com/validatorjs/validator.js/pull/1213), + [#1217](https://github.com/validatorjs/validator.js/pull/1217), + [#1234](https://github.com/validatorjs/validator.js/pull/1234)) #### 12.1.0 - ES module for webpack tree shaking - ([#1015](https://github.com/chriso/validator.js/pull/1015)) + ([#1015](https://github.com/validatorjs/validator.js/pull/1015)) - Updated `isIP()` to accept scoped IPv6 addresses - ([#1160](https://github.com/chriso/validator.js/pull/1160)) + ([#1160](https://github.com/validatorjs/validator.js/pull/1160)) - New and improved locales - ([#1162](https://github.com/chriso/validator.js/pull/1162), - [#1183](https://github.com/chriso/validator.js/pull/1183), - [#1187](https://github.com/chriso/validator.js/pull/1187), - [#1191](https://github.com/chriso/validator.js/pull/1191)) + ([#1162](https://github.com/validatorjs/validator.js/pull/1162), + [#1183](https://github.com/validatorjs/validator.js/pull/1183), + [#1187](https://github.com/validatorjs/validator.js/pull/1187), + [#1191](https://github.com/validatorjs/validator.js/pull/1191)) #### 12.0.0 - Added `isOctal()` validator - ([#1153](https://github.com/chriso/validator.js/pull/1153)) + ([#1153](https://github.com/validatorjs/validator.js/pull/1153)) - Added `isSlug()` validator - ([#1096](https://github.com/chriso/validator.js/pull/1096)) + ([#1096](https://github.com/validatorjs/validator.js/pull/1096)) - Added `isBIC()` validator for bank identification codes - ([#1071](https://github.com/chriso/validator.js/pull/1071)) + ([#1071](https://github.com/validatorjs/validator.js/pull/1071)) - Allow uppercase chars in `isHash()` - ([#1062](https://github.com/chriso/validator.js/pull/1062)) + ([#1062](https://github.com/validatorjs/validator.js/pull/1062)) - Allow additional prefixes in `isHexadecimal()` - ([#1147](https://github.com/chriso/validator.js/pull/1147)) + ([#1147](https://github.com/validatorjs/validator.js/pull/1147)) - Allow additional separators in `isMACAddress()` - ([#1065](https://github.com/chriso/validator.js/pull/1065)) + ([#1065](https://github.com/validatorjs/validator.js/pull/1065)) - Better defaults for `isLength()` - ([#1070](https://github.com/chriso/validator.js/pull/1070)) + ([#1070](https://github.com/validatorjs/validator.js/pull/1070)) - Bug fixes - ([#1074](https://github.com/chriso/validator.js/pull/1074)) + ([#1074](https://github.com/validatorjs/validator.js/pull/1074)) - New and improved locales - ([#1059](https://github.com/chriso/validator.js/pull/1059), - [#1060](https://github.com/chriso/validator.js/pull/1060), - [#1069](https://github.com/chriso/validator.js/pull/1069), - [#1073](https://github.com/chriso/validator.js/pull/1073), - [#1082](https://github.com/chriso/validator.js/pull/1082), - [#1092](https://github.com/chriso/validator.js/pull/1092), - [#1121](https://github.com/chriso/validator.js/pull/1121), - [#1125](https://github.com/chriso/validator.js/pull/1125), - [#1132](https://github.com/chriso/validator.js/pull/1132), - [#1152](https://github.com/chriso/validator.js/pull/1152), - [#1165](https://github.com/chriso/validator.js/pull/1165), - [#1166](https://github.com/chriso/validator.js/pull/1166), - [#1174](https://github.com/chriso/validator.js/pull/1174)) + ([#1059](https://github.com/validatorjs/validator.js/pull/1059), + [#1060](https://github.com/validatorjs/validator.js/pull/1060), + [#1069](https://github.com/validatorjs/validator.js/pull/1069), + [#1073](https://github.com/validatorjs/validator.js/pull/1073), + [#1082](https://github.com/validatorjs/validator.js/pull/1082), + [#1092](https://github.com/validatorjs/validator.js/pull/1092), + [#1121](https://github.com/validatorjs/validator.js/pull/1121), + [#1125](https://github.com/validatorjs/validator.js/pull/1125), + [#1132](https://github.com/validatorjs/validator.js/pull/1132), + [#1152](https://github.com/validatorjs/validator.js/pull/1152), + [#1165](https://github.com/validatorjs/validator.js/pull/1165), + [#1166](https://github.com/validatorjs/validator.js/pull/1166), + [#1174](https://github.com/validatorjs/validator.js/pull/1174)) #### 11.1.0 - Code coverage improvements - ([#1024](https://github.com/chriso/validator.js/pull/1024)) + ([#1024](https://github.com/validatorjs/validator.js/pull/1024)) - New and improved locales - ([#1035](https://github.com/chriso/validator.js/pull/1035), - [#1040](https://github.com/chriso/validator.js/pull/1040), - [#1041](https://github.com/chriso/validator.js/pull/1041), - [#1048](https://github.com/chriso/validator.js/pull/1048), - [#1049](https://github.com/chriso/validator.js/pull/1049), - [#1052](https://github.com/chriso/validator.js/pull/1052), - [#1054](https://github.com/chriso/validator.js/pull/1054), - [#1055](https://github.com/chriso/validator.js/pull/1055), - [#1056](https://github.com/chriso/validator.js/pull/1056), - [#1057](https://github.com/chriso/validator.js/pull/1057)) + ([#1035](https://github.com/validatorjs/validator.js/pull/1035), + [#1040](https://github.com/validatorjs/validator.js/pull/1040), + [#1041](https://github.com/validatorjs/validator.js/pull/1041), + [#1048](https://github.com/validatorjs/validator.js/pull/1048), + [#1049](https://github.com/validatorjs/validator.js/pull/1049), + [#1052](https://github.com/validatorjs/validator.js/pull/1052), + [#1054](https://github.com/validatorjs/validator.js/pull/1054), + [#1055](https://github.com/validatorjs/validator.js/pull/1055), + [#1056](https://github.com/validatorjs/validator.js/pull/1056), + [#1057](https://github.com/validatorjs/validator.js/pull/1057)) #### 11.0.0 - Added a `isBase32()` validator - ([#1023](https://github.com/chriso/validator.js/pull/1023)) + ([#1023](https://github.com/validatorjs/validator.js/pull/1023)) - Updated `isEmail()` to validate display names according to RFC2822 - ([#1004](https://github.com/chriso/validator.js/pull/1004)) + ([#1004](https://github.com/validatorjs/validator.js/pull/1004)) - Updated `isEmail()` to check total email length - ([#1007](https://github.com/chriso/validator.js/pull/1007)) + ([#1007](https://github.com/validatorjs/validator.js/pull/1007)) - The internal `toString()` util is no longer exported - ([0277eb](https://github.com/chriso/validator.js/commit/0277eb00d245a3479af52adf7d927d4036895650)) + ([0277eb](https://github.com/validatorjs/validator.js/commit/0277eb00d245a3479af52adf7d927d4036895650)) - New and improved locales - ([#999](https://github.com/chriso/validator.js/pull/999), - [#1010](https://github.com/chriso/validator.js/pull/1010), - [#1017](https://github.com/chriso/validator.js/pull/1017), - [#1022](https://github.com/chriso/validator.js/pull/1022), - [#1031](https://github.com/chriso/validator.js/pull/1031), - [#1032](https://github.com/chriso/validator.js/pull/1032)) + ([#999](https://github.com/validatorjs/validator.js/pull/999), + [#1010](https://github.com/validatorjs/validator.js/pull/1010), + [#1017](https://github.com/validatorjs/validator.js/pull/1017), + [#1022](https://github.com/validatorjs/validator.js/pull/1022), + [#1031](https://github.com/validatorjs/validator.js/pull/1031), + [#1032](https://github.com/validatorjs/validator.js/pull/1032)) #### 10.11.0 - Fix imports like `import .. from "validator/lib/.."` - ([#961](https://github.com/chriso/validator.js/pull/961)) + ([#961](https://github.com/validatorjs/validator.js/pull/961)) - New locale - ([#958](https://github.com/chriso/validator.js/pull/958)) + ([#958](https://github.com/validatorjs/validator.js/pull/958)) #### 10.10.0 - `isISO8601()` strict mode now works in the browser - ([#932](https://github.com/chriso/validator.js/pull/932)) + ([#932](https://github.com/validatorjs/validator.js/pull/932)) - New and improved locales - ([#931](https://github.com/chriso/validator.js/pull/931), - [#933](https://github.com/chriso/validator.js/pull/933), - [#947](https://github.com/chriso/validator.js/pull/947), - [#950](https://github.com/chriso/validator.js/pull/950)) + ([#931](https://github.com/validatorjs/validator.js/pull/931), + [#933](https://github.com/validatorjs/validator.js/pull/933), + [#947](https://github.com/validatorjs/validator.js/pull/947), + [#950](https://github.com/validatorjs/validator.js/pull/950)) #### 10.9.0 - Added an option to `isURL()` to reject email-like URLs - ([#901](https://github.com/chriso/validator.js/pull/901)) + ([#901](https://github.com/validatorjs/validator.js/pull/901)) - Added a `strict` option to `isISO8601()` - ([#910](https://github.com/chriso/validator.js/pull/910)) + ([#910](https://github.com/validatorjs/validator.js/pull/910)) - Relaxed `isJWT()` signature requirements - ([#906](https://github.com/chriso/validator.js/pull/906)) + ([#906](https://github.com/validatorjs/validator.js/pull/906)) - New and improved locales - ([#899](https://github.com/chriso/validator.js/pull/899), - [#904](https://github.com/chriso/validator.js/pull/904), - [#913](https://github.com/chriso/validator.js/pull/913), - [#916](https://github.com/chriso/validator.js/pull/916), - [#925](https://github.com/chriso/validator.js/pull/925), - [#928](https://github.com/chriso/validator.js/pull/928)) + ([#899](https://github.com/validatorjs/validator.js/pull/899), + [#904](https://github.com/validatorjs/validator.js/pull/904), + [#913](https://github.com/validatorjs/validator.js/pull/913), + [#916](https://github.com/validatorjs/validator.js/pull/916), + [#925](https://github.com/validatorjs/validator.js/pull/925), + [#928](https://github.com/validatorjs/validator.js/pull/928)) #### 10.8.0 - Added `isIdentityCard()` - ([#846](https://github.com/chriso/validator.js/pull/846)) + ([#846](https://github.com/validatorjs/validator.js/pull/846)) - Better error when validators are passed an invalid type - ([#895](https://github.com/chriso/validator.js/pull/895)) + ([#895](https://github.com/validatorjs/validator.js/pull/895)) - Locales are now exported - ([#890](https://github.com/chriso/validator.js/pull/890), - [#892](https://github.com/chriso/validator.js/pull/892)) + ([#890](https://github.com/validatorjs/validator.js/pull/890), + [#892](https://github.com/validatorjs/validator.js/pull/892)) - New locale - ([#896](https://github.com/chriso/validator.js/pull/896)) + ([#896](https://github.com/validatorjs/validator.js/pull/896)) #### 10.7.1 - Ignore case when checking URL protocol - ([#887](https://github.com/chriso/validator.js/issues/887)) + ([#887](https://github.com/validatorjs/validator.js/issues/887)) - Locale fix - ([#889](https://github.com/chriso/validator.js/pull/889)) + ([#889](https://github.com/validatorjs/validator.js/pull/889)) #### 10.7.0 - Added `isMagnetURI()` to validate [magnet URIs](https://en.wikipedia.org/wiki/Magnet_URI_scheme) - ([#884](https://github.com/chriso/validator.js/pull/884)) + ([#884](https://github.com/validatorjs/validator.js/pull/884)) - Added `isJWT()` to validate [JSON web tokens](https://en.wikipedia.org/wiki/JSON_Web_Token) - ([#885](https://github.com/chriso/validator.js/pull/885)) + ([#885](https://github.com/validatorjs/validator.js/pull/885)) #### 10.6.0 - Updated `isMobilePhone()` to match any locale's pattern by default - ([#874](https://github.com/chriso/validator.js/pull/874)) + ([#874](https://github.com/validatorjs/validator.js/pull/874)) - Added an option to ignore whitespace in `isEmpty()` - ([#880](https://github.com/chriso/validator.js/pull/880)) + ([#880](https://github.com/validatorjs/validator.js/pull/880)) - New and improved locales - ([#878](https://github.com/chriso/validator.js/pull/878), - [#879](https://github.com/chriso/validator.js/pull/879)) + ([#878](https://github.com/validatorjs/validator.js/pull/878), + [#879](https://github.com/validatorjs/validator.js/pull/879)) #### 10.5.0 - Disabled domain-specific email validation - ([#873](https://github.com/chriso/validator.js/pull/873)) + ([#873](https://github.com/validatorjs/validator.js/pull/873)) - Added support for IP hostnames in `isEmail()` - ([#845](https://github.com/chriso/validator.js/pull/845)) + ([#845](https://github.com/validatorjs/validator.js/pull/845)) - Added a `no_symbols` option to `isNumeric()` - ([#848](https://github.com/chriso/validator.js/pull/848)) + ([#848](https://github.com/validatorjs/validator.js/pull/848)) - Added a `no_colons` option to `isMACAddress()` - ([#849](https://github.com/chriso/validator.js/pull/849)) + ([#849](https://github.com/validatorjs/validator.js/pull/849)) - Updated `isURL()` to reject protocol relative URLs unless a flag is set - ([#860](https://github.com/chriso/validator.js/issues/860)) + ([#860](https://github.com/validatorjs/validator.js/issues/860)) - New and improved locales - ([#801](https://github.com/chriso/validator.js/pull/801), - [#856](https://github.com/chriso/validator.js/pull/856), - [#859](https://github.com/chriso/validator.js/issues/859), - [#861](https://github.com/chriso/validator.js/pull/861), - [#862](https://github.com/chriso/validator.js/pull/862), - [#863](https://github.com/chriso/validator.js/pull/863), - [#864](https://github.com/chriso/validator.js/pull/864), - [#870](https://github.com/chriso/validator.js/pull/870), - [#872](https://github.com/chriso/validator.js/pull/872)) + ([#801](https://github.com/validatorjs/validator.js/pull/801), + [#856](https://github.com/validatorjs/validator.js/pull/856), + [#859](https://github.com/validatorjs/validator.js/issues/859), + [#861](https://github.com/validatorjs/validator.js/pull/861), + [#862](https://github.com/validatorjs/validator.js/pull/862), + [#863](https://github.com/validatorjs/validator.js/pull/863), + [#864](https://github.com/validatorjs/validator.js/pull/864), + [#870](https://github.com/validatorjs/validator.js/pull/870), + [#872](https://github.com/validatorjs/validator.js/pull/872)) #### 10.4.0 - Added an `isIPRange()` validator - ([#842](https://github.com/chriso/validator.js/pull/842)) + ([#842](https://github.com/validatorjs/validator.js/pull/842)) - Accept an array of locales in `isMobilePhone()` - ([#742](https://github.com/chriso/validator.js/pull/742)) + ([#742](https://github.com/validatorjs/validator.js/pull/742)) - New locale - ([#843](https://github.com/chriso/validator.js/pull/843)) + ([#843](https://github.com/validatorjs/validator.js/pull/843)) #### 10.3.0 - Strict Gmail validation in `isEmail()` - ([#832](https://github.com/chriso/validator.js/pull/832)) + ([#832](https://github.com/validatorjs/validator.js/pull/832)) - New locales - ([#831](https://github.com/chriso/validator.js/pull/831), - [#835](https://github.com/chriso/validator.js/pull/835), - [#836](https://github.com/chriso/validator.js/pull/836)) + ([#831](https://github.com/validatorjs/validator.js/pull/831), + [#835](https://github.com/validatorjs/validator.js/pull/835), + [#836](https://github.com/validatorjs/validator.js/pull/836)) #### 10.2.0 - Export the list of supported locales in `isPostalCode()` - ([#830](https://github.com/chriso/validator.js/pull/830)) + ([#830](https://github.com/validatorjs/validator.js/pull/830)) #### 10.1.0 - Added an `isISO31661Alpha3()` validator - ([#809](https://github.com/chriso/validator.js/pull/809)) + ([#809](https://github.com/validatorjs/validator.js/pull/809)) #### 10.0.0 - Allow floating points in `isNumeric()` - ([#810](https://github.com/chriso/validator.js/pull/810)) + ([#810](https://github.com/validatorjs/validator.js/pull/810)) - Disallow GMail addresses with multiple consecutive dots, or leading/trailing dots - ([#820](https://github.com/chriso/validator.js/pull/820)) + ([#820](https://github.com/validatorjs/validator.js/pull/820)) - Added an `isRFC3339()` validator - ([#816](https://github.com/chriso/validator.js/pull/816)) + ([#816](https://github.com/validatorjs/validator.js/pull/816)) - Reject domain parts longer than 63 octets in `isFQDN()`, `isURL()` and `isEmail()` - ([bb3e542](https://github.com/chriso/validator.js/commit/bb3e542)) + ([bb3e542](https://github.com/validatorjs/validator.js/commit/bb3e542)) - Added a new Amex prefix to `isCreditCard()` - ([#805](https://github.com/chriso/validator.js/pull/805)) + ([#805](https://github.com/validatorjs/validator.js/pull/805)) - Fixed `isFloat()` min/max/gt/lt filters when a locale with a comma decimal is used - ([2b70821](https://github.com/chriso/validator.js/commit/2b70821)) + ([2b70821](https://github.com/validatorjs/validator.js/commit/2b70821)) - Normalize Yandex emails - ([#807](https://github.com/chriso/validator.js/pull/807)) + ([#807](https://github.com/validatorjs/validator.js/pull/807)) - New locales - ([#803](https://github.com/chriso/validator.js/pull/803)) + ([#803](https://github.com/validatorjs/validator.js/pull/803)) #### 9.4.1 - Patched a [REDOS](https://en.wikipedia.org/wiki/ReDoS) vulnerability in `isDataURI` - New and improved locales - ([#788](https://github.com/chriso/validator.js/pull/788)) + ([#788](https://github.com/validatorjs/validator.js/pull/788)) #### 9.4.0 - Added an option to `isMobilePhone` to require a country code - ([#769](https://github.com/chriso/validator.js/pull/769)) + ([#769](https://github.com/validatorjs/validator.js/pull/769)) - New and improved locales - ([#785](https://github.com/chriso/validator.js/pull/785)) + ([#785](https://github.com/validatorjs/validator.js/pull/785)) #### 9.3.0 - New and improved locales - ([#763](https://github.com/chriso/validator.js/pull/763), - [#768](https://github.com/chriso/validator.js/pull/768), - [#774](https://github.com/chriso/validator.js/pull/774), - [#777](https://github.com/chriso/validator.js/pull/777), - [#779](https://github.com/chriso/validator.js/pull/779)) + ([#763](https://github.com/validatorjs/validator.js/pull/763), + [#768](https://github.com/validatorjs/validator.js/pull/768), + [#774](https://github.com/validatorjs/validator.js/pull/774), + [#777](https://github.com/validatorjs/validator.js/pull/777), + [#779](https://github.com/validatorjs/validator.js/pull/779)) #### 9.2.0 - Added an `isMimeType()` validator - ([#760](https://github.com/chriso/validator.js/pull/760)) + ([#760](https://github.com/validatorjs/validator.js/pull/760)) - New and improved locales - ([#753](https://github.com/chriso/validator.js/pull/753), - [#755](https://github.com/chriso/validator.js/pull/755), - [#764](https://github.com/chriso/validator.js/pull/764)) + ([#753](https://github.com/validatorjs/validator.js/pull/753), + [#755](https://github.com/validatorjs/validator.js/pull/755), + [#764](https://github.com/validatorjs/validator.js/pull/764)) #### 9.1.2 - Fixed a bug with the `isFloat` validator - ([#752](https://github.com/chriso/validator.js/pull/752)) + ([#752](https://github.com/validatorjs/validator.js/pull/752)) #### 9.1.1 - Locale fixes - ([#738](https://github.com/chriso/validator.js/pull/738), - [#739](https://github.com/chriso/validator.js/pull/739)) + ([#738](https://github.com/validatorjs/validator.js/pull/738), + [#739](https://github.com/validatorjs/validator.js/pull/739)) #### 9.1.0 - Added an `isISO31661Alpha2()` validator - ([#734](https://github.com/chriso/validator.js/pull/734)) + ([#734](https://github.com/validatorjs/validator.js/pull/734)) - New locales - ([#735](https://github.com/chriso/validator.js/pull/735), - [#737](https://github.com/chriso/validator.js/pull/737)) + ([#735](https://github.com/validatorjs/validator.js/pull/735), + [#737](https://github.com/validatorjs/validator.js/pull/737)) #### 9.0.0 - `normalizeEmail()` no longer validates the email address - ([#725](https://github.com/chriso/validator.js/pull/725)) + ([#725](https://github.com/validatorjs/validator.js/pull/725)) - Added locale-aware validation to `isFloat()` and `isDecimal()` - ([#721](https://github.com/chriso/validator.js/pull/721)) + ([#721](https://github.com/validatorjs/validator.js/pull/721)) - Added an `isPort()` validator - ([#733](https://github.com/chriso/validator.js/pull/733)) + ([#733](https://github.com/validatorjs/validator.js/pull/733)) - New locales - ([#731](https://github.com/chriso/validator.js/pull/731)) + ([#731](https://github.com/validatorjs/validator.js/pull/731)) #### 8.2.0 - Added an `isHash()` validator - ([#711](https://github.com/chriso/validator.js/pull/711)) + ([#711](https://github.com/validatorjs/validator.js/pull/711)) - Control decimal places in `isCurrency()` - ([#713](https://github.com/chriso/validator.js/pull/713)) + ([#713](https://github.com/validatorjs/validator.js/pull/713)) - New and improved locales - ([#700](https://github.com/chriso/validator.js/pull/700), - [#701](https://github.com/chriso/validator.js/pull/701), - [#714](https://github.com/chriso/validator.js/pull/714), - [#715](https://github.com/chriso/validator.js/pull/715), - [#718](https://github.com/chriso/validator.js/pull/718)) + ([#700](https://github.com/validatorjs/validator.js/pull/700), + [#701](https://github.com/validatorjs/validator.js/pull/701), + [#714](https://github.com/validatorjs/validator.js/pull/714), + [#715](https://github.com/validatorjs/validator.js/pull/715), + [#718](https://github.com/validatorjs/validator.js/pull/718)) #### 8.1.0 - Fix `require('validator/lib/isIS8601')` calls - ([#688](https://github.com/chriso/validator.js/issues/688)) + ([#688](https://github.com/validatorjs/validator.js/issues/688)) - Added an `isLatLong()` and `isPostalCode()` validator - ([#684](https://github.com/chriso/validator.js/pull/684)) + ([#684](https://github.com/validatorjs/validator.js/pull/684)) - Allow comma in email display names - ([#692](https://github.com/chriso/validator.js/pull/692)) + ([#692](https://github.com/validatorjs/validator.js/pull/692)) - Add missing string to `unescape()` - ([#690](https://github.com/chriso/validator.js/pull/690)) + ([#690](https://github.com/validatorjs/validator.js/pull/690)) - Fix `isMobilePhone()` with Node <= 6.x - ([#681](https://github.com/chriso/validator.js/issues/681)) + ([#681](https://github.com/validatorjs/validator.js/issues/681)) - New locales - ([#695](https://github.com/chriso/validator.js/pull/695)) + ([#695](https://github.com/validatorjs/validator.js/pull/695)) #### 8.0.0 - `isURL()` now requires the `require_tld: false` option to validate `localhost` - ([#675](https://github.com/chriso/validator.js/issues/675)) + ([#675](https://github.com/validatorjs/validator.js/issues/675)) - `isURL()` now rejects URLs that are protocol only - ([#642](https://github.com/chriso/validator.js/issues/642)) + ([#642](https://github.com/validatorjs/validator.js/issues/642)) - Fixed a bug where `isMobilePhone()` would silently return false if the locale was invalid or unsupported - ([#657](https://github.com/chriso/validator.js/issues/657)) + ([#657](https://github.com/validatorjs/validator.js/issues/657)) #### 7.2.0 - Added an option to validate any phone locale - ([#663](https://github.com/chriso/validator.js/pull/663)) + ([#663](https://github.com/validatorjs/validator.js/pull/663)) - Fixed a bug in credit card validation - ([#672](https://github.com/chriso/validator.js/pull/672)) + ([#672](https://github.com/validatorjs/validator.js/pull/672)) - Disallow whitespace, including unicode whitespace, in TLDs - ([#677](https://github.com/chriso/validator.js/pull/677)) + ([#677](https://github.com/validatorjs/validator.js/pull/677)) - New locales - ([#673](https://github.com/chriso/validator.js/pull/673), - [#676](https://github.com/chriso/validator.js/pull/676)) + ([#673](https://github.com/validatorjs/validator.js/pull/673), + [#676](https://github.com/validatorjs/validator.js/pull/676)) #### 7.1.0 - Added an `isISRC()` validator for [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code) - ([#660](https://github.com/chriso/validator.js/pull/660)) + ([#660](https://github.com/validatorjs/validator.js/pull/660)) - Fixed a bug in credit card validation - ([#670](https://github.com/chriso/validator.js/pull/670)) + ([#670](https://github.com/validatorjs/validator.js/pull/670)) - Reduced the maximum allowed address in `isEmail()` based on [RFC3696 errata](http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690) - ([#655](https://github.com/chriso/validator.js/issues/655)) + ([#655](https://github.com/validatorjs/validator.js/issues/655)) - New locales - ([#647](https://github.com/chriso/validator.js/pull/647), - [#667](https://github.com/chriso/validator.js/pull/667), - [#667](https://github.com/chriso/validator.js/pull/667), - [#671](https://github.com/chriso/validator.js/pull/671)) + ([#647](https://github.com/validatorjs/validator.js/pull/647), + [#667](https://github.com/validatorjs/validator.js/pull/667), + [#667](https://github.com/validatorjs/validator.js/pull/667), + [#671](https://github.com/validatorjs/validator.js/pull/671)) #### 7.0.0 @@ -527,290 +527,290 @@ #### 6.3.0 - Allow values like `-.01` in `isFloat()` - ([#618](https://github.com/chriso/validator.js/issues/618)) + ([#618](https://github.com/validatorjs/validator.js/issues/618)) - New locales - ([#616](https://github.com/chriso/validator.js/pull/616), - [#622](https://github.com/chriso/validator.js/pull/622), - [#627](https://github.com/chriso/validator.js/pull/627), - [#630](https://github.com/chriso/validator.js/pull/630)) + ([#616](https://github.com/validatorjs/validator.js/pull/616), + [#622](https://github.com/validatorjs/validator.js/pull/622), + [#627](https://github.com/validatorjs/validator.js/pull/627), + [#630](https://github.com/validatorjs/validator.js/pull/630)) #### 6.2.1 - Disallow `<` and `>` in URLs - ([#613](https://github.com/chriso/validator.js/issues/613)) + ([#613](https://github.com/validatorjs/validator.js/issues/613)) - New locales - ([#610](https://github.com/chriso/validator.js/pull/610)) + ([#610](https://github.com/validatorjs/validator.js/pull/610)) #### 6.2.0 - Added an option to require an email display name - ([#607](https://github.com/chriso/validator.js/pull/607)) + ([#607](https://github.com/validatorjs/validator.js/pull/607)) - Added support for `lt` and `gt` to `isInt()` - ([#588](https://github.com/chriso/validator.js/pull/588)) + ([#588](https://github.com/validatorjs/validator.js/pull/588)) - New locales - ([#601](https://github.com/chriso/validator.js/pull/601)) + ([#601](https://github.com/validatorjs/validator.js/pull/601)) #### 6.1.0 - Added support for greater or less than in `isFloat()` - ([#544](https://github.com/chriso/validator.js/issues/544)) + ([#544](https://github.com/validatorjs/validator.js/issues/544)) - Added support for ISSN validation via `isISSN()` - ([#593](https://github.com/chriso/validator.js/pull/593)) + ([#593](https://github.com/validatorjs/validator.js/pull/593)) - Fixed a bug in `normalizeEmail()` - ([#594](https://github.com/chriso/validator.js/issues/594)) + ([#594](https://github.com/validatorjs/validator.js/issues/594)) - New locales - ([#585](https://github.com/chriso/validator.js/pull/585)) + ([#585](https://github.com/validatorjs/validator.js/pull/585)) #### 6.0.0 - Renamed `isNull()` to `isEmpty()` - ([#574](https://github.com/chriso/validator.js/issues/574)) + ([#574](https://github.com/validatorjs/validator.js/issues/574)) - Backslash is now escaped in `escape()` - ([#516](https://github.com/chriso/validator.js/issues/516)) + ([#516](https://github.com/validatorjs/validator.js/issues/516)) - Improved `normalizeEmail()` - ([#583](https://github.com/chriso/validator.js/pull/583)) + ([#583](https://github.com/validatorjs/validator.js/pull/583)) - Allow leading zeroes by default in `isInt()` - ([#532](https://github.com/chriso/validator.js/pull/532)) + ([#532](https://github.com/validatorjs/validator.js/pull/532)) #### 5.7.0 - Added support for IPv6 in `isURL()` - ([#564](https://github.com/chriso/validator.js/issues/564)) + ([#564](https://github.com/validatorjs/validator.js/issues/564)) - Added support for urls without a host (e.g. `file:///foo.txt`) in `isURL()` - ([#563](https://github.com/chriso/validator.js/issues/563)) + ([#563](https://github.com/validatorjs/validator.js/issues/563)) - Added support for regular expressions in the `isURL()` host whitelist and blacklist - ([#562](https://github.com/chriso/validator.js/issues/562)) + ([#562](https://github.com/validatorjs/validator.js/issues/562)) - Added support for MasterCard 2-Series BIN - ([#576](https://github.com/chriso/validator.js/pull/576)) + ([#576](https://github.com/validatorjs/validator.js/pull/576)) - New locales - ([#575](https://github.com/chriso/validator.js/pull/575), - [#552](https://github.com/chriso/validator.js/issues/552)) + ([#575](https://github.com/validatorjs/validator.js/pull/575), + [#552](https://github.com/validatorjs/validator.js/issues/552)) #### 5.6.0 - Added an `isMD5()` validator - ([#557](https://github.com/chriso/validator.js/pull/557)) + ([#557](https://github.com/validatorjs/validator.js/pull/557)) - Fixed an exceptional case in `isDate()` - ([#566](https://github.com/chriso/validator.js/pull/566)) + ([#566](https://github.com/validatorjs/validator.js/pull/566)) - New locales - ([#559](https://github.com/chriso/validator.js/pull/559), - [#568](https://github.com/chriso/validator.js/pull/568), - [#571](https://github.com/chriso/validator.js/pull/571), - [#573](https://github.com/chriso/validator.js/pull/573)) + ([#559](https://github.com/validatorjs/validator.js/pull/559), + [#568](https://github.com/validatorjs/validator.js/pull/568), + [#571](https://github.com/validatorjs/validator.js/pull/571), + [#573](https://github.com/validatorjs/validator.js/pull/573)) #### 5.5.0 - Fixed a regex denial of service in `trim()` and `rtrim()` - ([#556](https://github.com/chriso/validator.js/pull/556)) + ([#556](https://github.com/validatorjs/validator.js/pull/556)) - Added an Algerian locale to `isMobilePhone()` - ([#540](https://github.com/chriso/validator.js/pull/540)) + ([#540](https://github.com/validatorjs/validator.js/pull/540)) - Fixed the Hungarian locale in `isAlpha()` and `isAlphanumeric()` - ([#541](https://github.com/chriso/validator.js/pull/541)) + ([#541](https://github.com/validatorjs/validator.js/pull/541)) - Added a Polish locale to `isMobilePhone()` - ([#545](https://github.com/chriso/validator.js/pull/545)) + ([#545](https://github.com/validatorjs/validator.js/pull/545)) #### 5.4.0 - Accept Union Pay credit cards in `isCreditCard()` - ([#539](https://github.com/chriso/validator.js/pull/539)) + ([#539](https://github.com/validatorjs/validator.js/pull/539)) - Added Danish locale to `isMobilePhone()` - ([#538](https://github.com/chriso/validator.js/pull/538)) + ([#538](https://github.com/validatorjs/validator.js/pull/538)) - Added Hungarian locales to `isAlpha()`, `isAlphanumeric()` and `isMobilePhone()` - ([#537](https://github.com/chriso/validator.js/pull/537)) + ([#537](https://github.com/validatorjs/validator.js/pull/537)) #### 5.3.0 - Added an `allow_leading_zeroes` option to `isInt()` - ([#532](https://github.com/chriso/validator.js/pull/532)) + ([#532](https://github.com/validatorjs/validator.js/pull/532)) - Adjust Chinese mobile phone validation - ([#523](https://github.com/chriso/validator.js/pull/523)) + ([#523](https://github.com/validatorjs/validator.js/pull/523)) - Added a Canadian locale to `isMobilePhone()` - ([#524](https://github.com/chriso/validator.js/issues/524)) + ([#524](https://github.com/validatorjs/validator.js/issues/524)) #### 5.2.0 - Added a `isDataURI()` validator - ([#521](https://github.com/chriso/validator.js/pull/521)) + ([#521](https://github.com/validatorjs/validator.js/pull/521)) - Added Czech locales - ([#522](https://github.com/chriso/validator.js/pull/522)) + ([#522](https://github.com/validatorjs/validator.js/pull/522)) - Fixed a bug with `isURL()` when protocol was missing and "://" appeared in the query - ([#518](https://github.com/chriso/validator.js/issues/518)) + ([#518](https://github.com/validatorjs/validator.js/issues/518)) #### 5.1.0 - Added a `unescape()` HTML function - ([#509](https://github.com/chriso/validator.js/pull/509)) + ([#509](https://github.com/validatorjs/validator.js/pull/509)) - Added a Malaysian locale to `isMobilePhone()` - ([#507](https://github.com/chriso/validator.js/pull/507)) + ([#507](https://github.com/validatorjs/validator.js/pull/507)) - Added Polish locales to `isAlpha()` and `isAlphanumeric()` - ([#506](https://github.com/chriso/validator.js/pull/506)) + ([#506](https://github.com/validatorjs/validator.js/pull/506)) - Added Turkish locales to `isAlpha()`, `isAlphanumeric()` and `isMobilePhone()` - ([#512](https://github.com/chriso/validator.js/pull/512)) + ([#512](https://github.com/validatorjs/validator.js/pull/512)) - Allow >1 underscore in hostnames when using `allow_underscores` - ([#510](https://github.com/chriso/validator.js/issues/510)) + ([#510](https://github.com/validatorjs/validator.js/issues/510)) #### 5.0.0 - Migrate to ES6 - ([#496](https://github.com/chriso/validator.js/pull/496)) + ([#496](https://github.com/validatorjs/validator.js/pull/496)) - Break the library up so that individual functions can be imported - ([#496](https://github.com/chriso/validator.js/pull/496)) + ([#496](https://github.com/validatorjs/validator.js/pull/496)) - Remove auto-coercion of input to a string - ([#496](https://github.com/chriso/validator.js/pull/496)) + ([#496](https://github.com/validatorjs/validator.js/pull/496)) - Remove the `extend()` function - ([#496](https://github.com/chriso/validator.js/pull/496)) + ([#496](https://github.com/validatorjs/validator.js/pull/496)) - Added Arabic locales to `isAlpha()` and `isAlphanumeric()` - ([#496](https://github.com/chriso/validator.js/pull/496#issuecomment-184781730)) + ([#496](https://github.com/validatorjs/validator.js/pull/496#issuecomment-184781730)) - Fix validation of very large base64 strings - ([#503](https://github.com/chriso/validator.js/pull/503)) + ([#503](https://github.com/validatorjs/validator.js/pull/503)) #### 4.9.0 - Added a Russian locale to `isAlpha()` and `isAlphanumeric()` - ([#499](https://github.com/chriso/validator.js/pull/499)) + ([#499](https://github.com/validatorjs/validator.js/pull/499)) - Remove the restriction on adjacent hyphens in hostnames - ([#500](https://github.com/chriso/validator.js/issues/500)) + ([#500](https://github.com/validatorjs/validator.js/issues/500)) #### 4.8.0 - Added Spanish, French, Portuguese and Dutch support for `isAlpha()` and `isAlphanumeric()` - ([#492](https://github.com/chriso/validator.js/pull/492)) + ([#492](https://github.com/validatorjs/validator.js/pull/492)) - Added a Brazilian locale to `isMobilePhone()` - ([#489](https://github.com/chriso/validator.js/pull/489)) + ([#489](https://github.com/validatorjs/validator.js/pull/489)) - Reject IPv4 addresses with invalid zero padding - ([#490](https://github.com/chriso/validator.js/pull/490)) + ([#490](https://github.com/validatorjs/validator.js/pull/490)) - Fix the client-side version when used with RequireJS - ([#494](https://github.com/chriso/validator.js/issues/494)) + ([#494](https://github.com/validatorjs/validator.js/issues/494)) #### 4.7.1 - Use [node-depd](https://github.com/dougwilson/nodejs-depd) to print deprecation notices - ([#487](https://github.com/chriso/validator.js/issues/487)) + ([#487](https://github.com/validatorjs/validator.js/issues/487)) #### 4.7.0 - Print a deprecation warning if validator input is not a string - ([1f67e1e](https://github.com/chriso/validator.js/commit/1f67e1e15198c0ae735151290dc8dc2bf14da254)). + ([1f67e1e](https://github.com/validatorjs/validator.js/commit/1f67e1e15198c0ae735151290dc8dc2bf14da254)). Note that this will be an error in v5. - Added a German locale to `isMobilePhone()`, `isAlpha()` and `isAlphanumeric()` - ([#477](https://github.com/chriso/validator.js/pull/477)) + ([#477](https://github.com/validatorjs/validator.js/pull/477)) - Added a Finnish locale to `isMobilePhone()` - ([#455](https://github.com/chriso/validator.js/pull/455)) + ([#455](https://github.com/validatorjs/validator.js/pull/455)) #### 4.6.1 - Fix coercion of objects: `Object.toString()` is `[object Object]` not `""` - ([a57f3c8](https://github.com/chriso/validator.js/commit/a57f3c843c715fba2664ee22ec80e9e28e88e0a6)) + ([a57f3c8](https://github.com/validatorjs/validator.js/commit/a57f3c843c715fba2664ee22ec80e9e28e88e0a6)) #### 4.6.0 - Added a Spanish locale to `isMobilePhone()` - ([#481](https://github.com/chriso/validator.js/pull/481)) + ([#481](https://github.com/validatorjs/validator.js/pull/481)) - Fix string coercion of objects created with `Object.create(null)` - ([#484](https://github.com/chriso/validator.js/issues/484)) + ([#484](https://github.com/validatorjs/validator.js/issues/484)) #### 4.5.2 - Fix a timezone issue with short-form ISO 8601 dates, e.g. `validator.isDate('2011-12-21')` - ([#480](https://github.com/chriso/validator.js/issues/480)) + ([#480](https://github.com/validatorjs/validator.js/issues/480)) #### 4.5.1 - Make `isLength()` / `isByteLength()` accept `{min, max}` as options object. - ([#474](https://github.com/chriso/validator.js/issues/474)) + ([#474](https://github.com/validatorjs/validator.js/issues/474)) #### 4.5.0 - Add validation for Indian mobile phone numbers - ([#471](https://github.com/chriso/validator.js/pull/471)) + ([#471](https://github.com/validatorjs/validator.js/pull/471)) - Tweak Greek and Chinese mobile phone validation - ([#467](https://github.com/chriso/validator.js/pull/467), - [#468](https://github.com/chriso/validator.js/pull/468)) + ([#467](https://github.com/validatorjs/validator.js/pull/467), + [#468](https://github.com/validatorjs/validator.js/pull/468)) - Fixed a bug in `isDate()` when validating ISO 8601 dates without a timezone - ([#472](https://github.com/chriso/validator.js/issues/472)) + ([#472](https://github.com/validatorjs/validator.js/issues/472)) #### 4.4.1 - Allow triple hyphens in IDNA hostnames - ([#466](https://github.com/chriso/validator.js/issues/466)) + ([#466](https://github.com/validatorjs/validator.js/issues/466)) #### 4.4.0 - Added `isMACAddress()` validator - ([#458](https://github.com/chriso/validator.js/pull/458)) + ([#458](https://github.com/validatorjs/validator.js/pull/458)) - Added `isWhitelisted()` validator - ([#462](https://github.com/chriso/validator.js/pull/462)) + ([#462](https://github.com/validatorjs/validator.js/pull/462)) - Added a New Zealand locale to `isMobilePhone()` - ([#452](https://github.com/chriso/validator.js/pull/452)) + ([#452](https://github.com/validatorjs/validator.js/pull/452)) - Added options to control GMail address normalization - ([#460](https://github.com/chriso/validator.js/pull/460)) + ([#460](https://github.com/validatorjs/validator.js/pull/460)) #### 4.3.0 - Support Ember CLI module definitions - ([#448](https://github.com/chriso/validator.js/pull/448)) + ([#448](https://github.com/validatorjs/validator.js/pull/448)) - Added a Vietnam locale to `isMobilePhone()` - ([#451](https://github.com/chriso/validator.js/pull/451)) + ([#451](https://github.com/validatorjs/validator.js/pull/451)) #### 4.2.1 - Fix `isDate()` handling of RFC2822 timezones - ([#447](https://github.com/chriso/validator.js/pull/447)) + ([#447](https://github.com/validatorjs/validator.js/pull/447)) #### 4.2.0 - Fix `isDate()` handling of ISO8601 timezones - ([#444](https://github.com/chriso/validator.js/pull/444)) + ([#444](https://github.com/validatorjs/validator.js/pull/444)) - Fix the incorrect `isFloat('.') === true` - ([#443](https://github.com/chriso/validator.js/pull/443)) + ([#443](https://github.com/validatorjs/validator.js/pull/443)) - Added a Norwegian locale to `isMobilePhone()` - ([#439](https://github.com/chriso/validator.js/pull/439)) + ([#439](https://github.com/validatorjs/validator.js/pull/439)) #### 4.1.0 - General `isDate()` improvements - ([#431](https://github.com/chriso/validator.js/pull/431)) + ([#431](https://github.com/validatorjs/validator.js/pull/431)) - Tests now require node 4.0+ - ([#438](https://github.com/chriso/validator.js/pull/438)) + ([#438](https://github.com/validatorjs/validator.js/pull/438)) #### 4.0.6 - Added a Taiwan locale to `isMobilePhone()` - ([#432](https://github.com/chriso/validator.js/pull/432)) + ([#432](https://github.com/validatorjs/validator.js/pull/432)) - Fixed a bug in `isBefore()` where it would return `null` - ([#436](https://github.com/chriso/validator.js/pull/436)) + ([#436](https://github.com/validatorjs/validator.js/pull/436)) #### 4.0.5 - Fixed a denial of service vulnerability in the `isEmail()` regex - ([#152](https://github.com/chriso/validator.js/issues/152#issuecomment-131874928)) + ([#152](https://github.com/validatorjs/validator.js/issues/152#issuecomment-131874928)) #### 4.0.4 - Reverted the leap year validation in `isDate()` as it introduced some regressions - ([#422](https://github.com/chriso/validator.js/issues/422), [#423](https://github.com/chriso/validator.js/issues/423)) + ([#422](https://github.com/validatorjs/validator.js/issues/422), [#423](https://github.com/validatorjs/validator.js/issues/423)) #### 4.0.3 - Added leap year validation to `isDate()` - ([#418](https://github.com/chriso/validator.js/pull/418)) + ([#418](https://github.com/validatorjs/validator.js/pull/418)) #### 4.0.2 - Fixed `isDecimal()` with an empty string - ([#419](https://github.com/chriso/validator.js/issues/419)) + ([#419](https://github.com/validatorjs/validator.js/issues/419)) #### 4.0.1 - Fixed `isByteLength()` with certain strings - ([09f0c6d](https://github.com/chriso/validator.js/commit/09f0c6d2321f0c78af6a7de42e91b63955e4c01e)) + ([09f0c6d](https://github.com/validatorjs/validator.js/commit/09f0c6d2321f0c78af6a7de42e91b63955e4c01e)) - Put length restrictions on email parts - ([#258](https://github.com/chriso/validator.js/issues/258#issuecomment-127173612)) + ([#258](https://github.com/validatorjs/validator.js/issues/258#issuecomment-127173612)) #### 4.0.0 - Simplified the `isEmail()` regex and fixed some edge cases - ([#258](https://github.com/chriso/validator.js/issues/258#issuecomment-127173612)) + ([#258](https://github.com/validatorjs/validator.js/issues/258#issuecomment-127173612)) - Added ISO 8601 date validation via `isISO8601()` - ([#373](https://github.com/chriso/validator.js/issues/373)) + ([#373](https://github.com/validatorjs/validator.js/issues/373)) diff --git a/README.md b/README.md index b2896b73f..db6da2679 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # validator.js [![NPM version][npm-image]][npm-url] -[![Build Status](https://travis-ci.org/validatorjs/validator.js.svg?branch=master)](https://travis-ci.org/validatorjs/validator.js) -[![codecov](https://codecov.io/gh/validatorjs/validator.js/branch/master/graph/badge.svg)](https://codecov.io/gh/validatorjs/validator.js) +[![CI][ci-image]][ci-url] +[![Coverage][codecov-image]][codecov-url] [![Downloads][downloads-image]][npm-url] [![Backers on Open Collective](https://opencollective.com/validatorjs/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/validatorjs/sponsors/badge.svg)](#sponsors) @@ -183,7 +183,7 @@ Sanitizer | Description ### XSS Sanitization -XSS sanitization was removed from the library in [2d5d6999](https://github.com/chriso/validator.js/commit/2d5d6999541add350fb396ef02dc42ca3215049e). +XSS sanitization was removed from the library in [2d5d6999](https://github.com/validatorjs/validator.js/commit/2d5d6999541add350fb396ef02dc42ca3215049e). For an alternative, have a look at Yahoo's [xss-filters library](https://github.com/yahoo/xss-filters) or at [DOMPurify](https://github.com/cure53/DOMPurify). @@ -253,8 +253,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [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 +[codecov-url]: https://codecov.io/gh/validatorjs/validator.js +[codecov-image]: https://codecov.io/gh/validatorjs/validator.js/branch/master/graph/badge.svg + +[ci-url]: https://github.com/validatorjs/validator.js/actions?query=workflow%3ACI +[ci-image]: https://github.com/validatorjs/validator.js/workflows/CI/badge.svg?branch=master [amd]: http://requirejs.org/docs/whyamd.html [bower]: http://bower.io/ diff --git a/bower.json b/bower.json index fb98d0ebc..427670cfc 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "validator-js", "main": "validator.js", - "homepage": "https://github.com/chriso/validator.js", + "homepage": "https://github.com/validatorjs/validator.js", "authors": [ "Chris O'Hara " ], diff --git a/index.js b/index.js deleted file mode 100644 index c45f62ef4..000000000 --- a/index.js +++ /dev/null @@ -1,305 +0,0 @@ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _toDate = _interopRequireDefault(require("./lib/toDate")); - -var _toFloat = _interopRequireDefault(require("./lib/toFloat")); - -var _toInt = _interopRequireDefault(require("./lib/toInt")); - -var _toBoolean = _interopRequireDefault(require("./lib/toBoolean")); - -var _equals = _interopRequireDefault(require("./lib/equals")); - -var _contains = _interopRequireDefault(require("./lib/contains")); - -var _matches = _interopRequireDefault(require("./lib/matches")); - -var _isEmail = _interopRequireDefault(require("./lib/isEmail")); - -var _isURL = _interopRequireDefault(require("./lib/isURL")); - -var _isMACAddress = _interopRequireDefault(require("./lib/isMACAddress")); - -var _isIP = _interopRequireDefault(require("./lib/isIP")); - -var _isIPRange = _interopRequireDefault(require("./lib/isIPRange")); - -var _isFQDN = _interopRequireDefault(require("./lib/isFQDN")); - -var _isDate = _interopRequireDefault(require("./lib/isDate")); - -var _isBoolean = _interopRequireDefault(require("./lib/isBoolean")); - -var _isLocale = _interopRequireDefault(require("./lib/isLocale")); - -var _isAlpha = _interopRequireWildcard(require("./lib/isAlpha")); - -var _isAlphanumeric = _interopRequireWildcard(require("./lib/isAlphanumeric")); - -var _isNumeric = _interopRequireDefault(require("./lib/isNumeric")); - -var _isPassportNumber = _interopRequireDefault(require("./lib/isPassportNumber")); - -var _isPort = _interopRequireDefault(require("./lib/isPort")); - -var _isLowercase = _interopRequireDefault(require("./lib/isLowercase")); - -var _isUppercase = _interopRequireDefault(require("./lib/isUppercase")); - -var _isIMEI = _interopRequireDefault(require("./lib/isIMEI")); - -var _isAscii = _interopRequireDefault(require("./lib/isAscii")); - -var _isFullWidth = _interopRequireDefault(require("./lib/isFullWidth")); - -var _isHalfWidth = _interopRequireDefault(require("./lib/isHalfWidth")); - -var _isVariableWidth = _interopRequireDefault(require("./lib/isVariableWidth")); - -var _isMultibyte = _interopRequireDefault(require("./lib/isMultibyte")); - -var _isSemVer = _interopRequireDefault(require("./lib/isSemVer")); - -var _isSurrogatePair = _interopRequireDefault(require("./lib/isSurrogatePair")); - -var _isInt = _interopRequireDefault(require("./lib/isInt")); - -var _isFloat = _interopRequireWildcard(require("./lib/isFloat")); - -var _isDecimal = _interopRequireDefault(require("./lib/isDecimal")); - -var _isHexadecimal = _interopRequireDefault(require("./lib/isHexadecimal")); - -var _isOctal = _interopRequireDefault(require("./lib/isOctal")); - -var _isDivisibleBy = _interopRequireDefault(require("./lib/isDivisibleBy")); - -var _isHexColor = _interopRequireDefault(require("./lib/isHexColor")); - -var _isRgbColor = _interopRequireDefault(require("./lib/isRgbColor")); - -var _isHSL = _interopRequireDefault(require("./lib/isHSL")); - -var _isISRC = _interopRequireDefault(require("./lib/isISRC")); - -var _isIBAN = _interopRequireDefault(require("./lib/isIBAN")); - -var _isBIC = _interopRequireDefault(require("./lib/isBIC")); - -var _isMD = _interopRequireDefault(require("./lib/isMD5")); - -var _isHash = _interopRequireDefault(require("./lib/isHash")); - -var _isJWT = _interopRequireDefault(require("./lib/isJWT")); - -var _isJSON = _interopRequireDefault(require("./lib/isJSON")); - -var _isEmpty = _interopRequireDefault(require("./lib/isEmpty")); - -var _isLength = _interopRequireDefault(require("./lib/isLength")); - -var _isByteLength = _interopRequireDefault(require("./lib/isByteLength")); - -var _isUUID = _interopRequireDefault(require("./lib/isUUID")); - -var _isMongoId = _interopRequireDefault(require("./lib/isMongoId")); - -var _isAfter = _interopRequireDefault(require("./lib/isAfter")); - -var _isBefore = _interopRequireDefault(require("./lib/isBefore")); - -var _isIn = _interopRequireDefault(require("./lib/isIn")); - -var _isCreditCard = _interopRequireDefault(require("./lib/isCreditCard")); - -var _isIdentityCard = _interopRequireDefault(require("./lib/isIdentityCard")); - -var _isEAN = _interopRequireDefault(require("./lib/isEAN")); - -var _isISIN = _interopRequireDefault(require("./lib/isISIN")); - -var _isISBN = _interopRequireDefault(require("./lib/isISBN")); - -var _isISSN = _interopRequireDefault(require("./lib/isISSN")); - -var _isTaxID = _interopRequireDefault(require("./lib/isTaxID")); - -var _isMobilePhone = _interopRequireWildcard(require("./lib/isMobilePhone")); - -var _isEthereumAddress = _interopRequireDefault(require("./lib/isEthereumAddress")); - -var _isCurrency = _interopRequireDefault(require("./lib/isCurrency")); - -var _isBtcAddress = _interopRequireDefault(require("./lib/isBtcAddress")); - -var _isISO = _interopRequireDefault(require("./lib/isISO8601")); - -var _isRFC = _interopRequireDefault(require("./lib/isRFC3339")); - -var _isISO31661Alpha = _interopRequireDefault(require("./lib/isISO31661Alpha2")); - -var _isISO31661Alpha2 = _interopRequireDefault(require("./lib/isISO31661Alpha3")); - -var _isBase = _interopRequireDefault(require("./lib/isBase32")); - -var _isBase2 = _interopRequireDefault(require("./lib/isBase58")); - -var _isBase3 = _interopRequireDefault(require("./lib/isBase64")); - -var _isDataURI = _interopRequireDefault(require("./lib/isDataURI")); - -var _isMagnetURI = _interopRequireDefault(require("./lib/isMagnetURI")); - -var _isMimeType = _interopRequireDefault(require("./lib/isMimeType")); - -var _isLatLong = _interopRequireDefault(require("./lib/isLatLong")); - -var _isPostalCode = _interopRequireWildcard(require("./lib/isPostalCode")); - -var _ltrim = _interopRequireDefault(require("./lib/ltrim")); - -var _rtrim = _interopRequireDefault(require("./lib/rtrim")); - -var _trim = _interopRequireDefault(require("./lib/trim")); - -var _escape = _interopRequireDefault(require("./lib/escape")); - -var _unescape = _interopRequireDefault(require("./lib/unescape")); - -var _stripLow = _interopRequireDefault(require("./lib/stripLow")); - -var _whitelist = _interopRequireDefault(require("./lib/whitelist")); - -var _blacklist = _interopRequireDefault(require("./lib/blacklist")); - -var _isWhitelisted = _interopRequireDefault(require("./lib/isWhitelisted")); - -var _normalizeEmail = _interopRequireDefault(require("./lib/normalizeEmail")); - -var _isSlug = _interopRequireDefault(require("./lib/isSlug")); - -var _isLicensePlate = _interopRequireDefault(require("./lib/isLicensePlate")); - -var _isStrongPassword = _interopRequireDefault(require("./lib/isStrongPassword")); - -var _isVAT = _interopRequireDefault(require("./lib/isVAT")); - -function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var version = '13.5.1'; -var validator = { - version: version, - toDate: _toDate.default, - toFloat: _toFloat.default, - toInt: _toInt.default, - toBoolean: _toBoolean.default, - equals: _equals.default, - contains: _contains.default, - matches: _matches.default, - isEmail: _isEmail.default, - isURL: _isURL.default, - isMACAddress: _isMACAddress.default, - isIP: _isIP.default, - isIPRange: _isIPRange.default, - isFQDN: _isFQDN.default, - isBoolean: _isBoolean.default, - isIBAN: _isIBAN.default, - isBIC: _isBIC.default, - isAlpha: _isAlpha.default, - isAlphaLocales: _isAlpha.locales, - isAlphanumeric: _isAlphanumeric.default, - isAlphanumericLocales: _isAlphanumeric.locales, - isNumeric: _isNumeric.default, - isPassportNumber: _isPassportNumber.default, - isPort: _isPort.default, - isLowercase: _isLowercase.default, - isUppercase: _isUppercase.default, - isAscii: _isAscii.default, - isFullWidth: _isFullWidth.default, - isHalfWidth: _isHalfWidth.default, - isVariableWidth: _isVariableWidth.default, - isMultibyte: _isMultibyte.default, - isSemVer: _isSemVer.default, - isSurrogatePair: _isSurrogatePair.default, - isInt: _isInt.default, - isIMEI: _isIMEI.default, - isFloat: _isFloat.default, - isFloatLocales: _isFloat.locales, - isDecimal: _isDecimal.default, - isHexadecimal: _isHexadecimal.default, - isOctal: _isOctal.default, - isDivisibleBy: _isDivisibleBy.default, - isHexColor: _isHexColor.default, - isRgbColor: _isRgbColor.default, - isHSL: _isHSL.default, - isISRC: _isISRC.default, - isMD5: _isMD.default, - isHash: _isHash.default, - isJWT: _isJWT.default, - isJSON: _isJSON.default, - isEmpty: _isEmpty.default, - isLength: _isLength.default, - isLocale: _isLocale.default, - isByteLength: _isByteLength.default, - isUUID: _isUUID.default, - isMongoId: _isMongoId.default, - isAfter: _isAfter.default, - isBefore: _isBefore.default, - isIn: _isIn.default, - isCreditCard: _isCreditCard.default, - isIdentityCard: _isIdentityCard.default, - isEAN: _isEAN.default, - isISIN: _isISIN.default, - isISBN: _isISBN.default, - isISSN: _isISSN.default, - isMobilePhone: _isMobilePhone.default, - isMobilePhoneLocales: _isMobilePhone.locales, - isPostalCode: _isPostalCode.default, - isPostalCodeLocales: _isPostalCode.locales, - isEthereumAddress: _isEthereumAddress.default, - isCurrency: _isCurrency.default, - isBtcAddress: _isBtcAddress.default, - isISO8601: _isISO.default, - isRFC3339: _isRFC.default, - isISO31661Alpha2: _isISO31661Alpha.default, - isISO31661Alpha3: _isISO31661Alpha2.default, - isBase32: _isBase.default, - isBase58: _isBase2.default, - isBase64: _isBase3.default, - isDataURI: _isDataURI.default, - isMagnetURI: _isMagnetURI.default, - isMimeType: _isMimeType.default, - isLatLong: _isLatLong.default, - ltrim: _ltrim.default, - rtrim: _rtrim.default, - trim: _trim.default, - escape: _escape.default, - unescape: _unescape.default, - stripLow: _stripLow.default, - whitelist: _whitelist.default, - blacklist: _blacklist.default, - isWhitelisted: _isWhitelisted.default, - normalizeEmail: _normalizeEmail.default, - toString: toString, - isSlug: _isSlug.default, - isStrongPassword: _isStrongPassword.default, - isTaxID: _isTaxID.default, - isDate: _isDate.default, - isLicensePlate: _isLicensePlate.default, - isVAT: _isVAT.default -}; -var _default = validator; -exports.default = _default; -module.exports = exports.default; -module.exports.default = exports.default; \ No newline at end of file diff --git a/package.json b/package.json index 9552c467d..8122a7f64 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "String validation and sanitization", "version": "13.5.1", "sideEffects": false, - "homepage": "https://github.com/chriso/validator.js", + "homepage": "https://github.com/validatorjs/validator.js", "files": [ "index.js", "es", @@ -25,18 +25,15 @@ ], "author": "Chris O'Hara ", "contributors": [ - { - "name": "Anthony Nandaa", - "url": "https://github.com/profnandaa" - } + "Anthony Nandaa (https://github.com/profnandaa)" ], "main": "index.js", "bugs": { - "url": "https://github.com/chriso/validator.js/issues" + "url": "https://github.com/validatorjs/validator.js/issues" }, "repository": { "type": "git", - "url": "https://github.com/chriso/validator.js.git" + "url": "git+https://github.com/validatorjs/validator.js.git" }, "devDependencies": { "@babel/cli": "^7.0.0", diff --git a/validator.js b/validator.js deleted file mode 100644 index 1c9653842..000000000 --- a/validator.js +++ /dev/null @@ -1,4776 +0,0 @@ -/*! - * Copyright (c) 2018 Chris O'Hara - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * 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 (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global.validator = factory()); -}(this, (function () { 'use strict'; - -function _typeof(obj) { - "@babel/helpers - typeof"; - - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - } - - return _typeof(obj); -} - -function _slicedToArray(arr, i) { - return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); -} - -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} - -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} - -function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; -} - -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); -} - -function _iterableToArrayLimit(arr, i) { - if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; - var _arr = []; - var _n = true; - var _d = false; - var _e = undefined; - - try { - for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { - _arr.push(_s.value); - - if (i && _arr.length === i) break; - } - } catch (err) { - _d = true; - _e = err; - } finally { - try { - if (!_n && _i["return"] != null) _i["return"](); - } finally { - if (_d) throw _e; - } - } - - return _arr; -} - -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(o); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); -} - -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - - for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; - - return arr2; -} - -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} - -function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} - -function _createForOfIteratorHelper(o, allowArrayLike) { - var it; - - if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { - if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { - if (it) o = it; - var i = 0; - - var F = function () {}; - - return { - s: F, - n: function () { - if (i >= o.length) return { - done: true - }; - return { - done: false, - value: o[i++] - }; - }, - e: function (e) { - throw e; - }, - f: F - }; - } - - throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - } - - var normalCompletion = true, - didErr = false, - err; - return { - s: function () { - it = o[Symbol.iterator](); - }, - n: function () { - var step = it.next(); - normalCompletion = step.done; - return step; - }, - e: function (e) { - didErr = true; - err = e; - }, - f: function () { - try { - if (!normalCompletion && it.return != null) it.return(); - } finally { - if (didErr) throw err; - } - } - }; -} - -function assertString(input) { - var isString = typeof input === 'string' || input instanceof String; - - if (!isString) { - var invalidType = _typeof(input); - - if (input === null) invalidType = 'null';else if (invalidType === 'object') invalidType = input.constructor.name; - throw new TypeError("Expected a string but received a ".concat(invalidType)); - } -} - -function toDate(date) { - assertString(date); - date = Date.parse(date); - return !isNaN(date) ? new Date(date) : null; -} - -var alpha = { - 'en-US': /^[A-Z]+$/i, - 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i, - 'bg-BG': /^[А-Я]+$/i, - 'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, - 'da-DK': /^[A-ZÆØÅ]+$/i, - 'de-DE': /^[A-ZÄÖÜß]+$/i, - 'el-GR': /^[Α-ώ]+$/i, - 'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i, - 'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i, - 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, - 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i, - 'nb-NO': /^[A-ZÆØÅ]+$/i, - 'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i, - 'nn-NO': /^[A-ZÆØÅ]+$/i, - 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, - 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, - 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, - 'ru-RU': /^[А-ЯЁ]+$/i, - 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i, - 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, - 'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i, - 'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i, - 'sv-SE': /^[A-ZÅÄÖ]+$/i, - 'th-TH': /^[ก-๐\s]+$/i, - 'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i, - 'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i, - 'vi-VN': /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i, - 'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i, - ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, - he: /^[א-ת]+$/, - fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i -}; -var alphanumeric = { - 'en-US': /^[0-9A-Z]+$/i, - 'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i, - 'bg-BG': /^[0-9А-Я]+$/i, - 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, - 'da-DK': /^[0-9A-ZÆØÅ]+$/i, - 'de-DE': /^[0-9A-ZÄÖÜß]+$/i, - 'el-GR': /^[0-9Α-ω]+$/i, - 'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i, - 'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, - 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i, - 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i, - 'nb-NO': /^[0-9A-ZÆØÅ]+$/i, - 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i, - 'nn-NO': /^[0-9A-ZÆØÅ]+$/i, - 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i, - 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, - 'ru-RU': /^[0-9А-ЯЁ]+$/i, - 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i, - 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, - 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i, - 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i, - 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i, - 'th-TH': /^[ก-๙\s]+$/i, - 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i, - 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i, - 'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i, - 'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i, - ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, - he: /^[0-9א-ת]+$/, - fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i -}; -var decimal = { - 'en-US': '.', - ar: '٫' -}; -var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM']; - -for (var locale, i = 0; i < englishLocales.length; i++) { - locale = "en-".concat(englishLocales[i]); - alpha[locale] = alpha['en-US']; - alphanumeric[locale] = alphanumeric['en-US']; - decimal[locale] = decimal['en-US']; -} // Source: http://www.localeplanet.com/java/ - - -var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE']; - -for (var _locale, _i = 0; _i < arabicLocales.length; _i++) { - _locale = "ar-".concat(arabicLocales[_i]); - alpha[_locale] = alpha.ar; - alphanumeric[_locale] = alphanumeric.ar; - decimal[_locale] = decimal.ar; -} - -var farsiLocales = ['IR', 'AF']; - -for (var _locale2, _i2 = 0; _i2 < farsiLocales.length; _i2++) { - _locale2 = "fa-".concat(farsiLocales[_i2]); - alphanumeric[_locale2] = alphanumeric.fa; - decimal[_locale2] = decimal.ar; -} // Source: https://en.wikipedia.org/wiki/Decimal_mark - - -var dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY']; -var commaDecimal = ['bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR', 'id-ID', 'it-IT', 'ku-IQ', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN']; - -for (var _i3 = 0; _i3 < dotDecimal.length; _i3++) { - decimal[dotDecimal[_i3]] = decimal['en-US']; -} - -for (var _i4 = 0; _i4 < commaDecimal.length; _i4++) { - decimal[commaDecimal[_i4]] = ','; -} - -alpha['fr-CA'] = alpha['fr-FR']; -alphanumeric['fr-CA'] = alphanumeric['fr-FR']; -alpha['pt-BR'] = alpha['pt-PT']; -alphanumeric['pt-BR'] = alphanumeric['pt-PT']; -decimal['pt-BR'] = decimal['pt-PT']; // see #862 - -alpha['pl-Pl'] = alpha['pl-PL']; -alphanumeric['pl-Pl'] = alphanumeric['pl-PL']; -decimal['pl-Pl'] = decimal['pl-PL']; // see #1455 - -alpha['fa-AF'] = alpha.fa; - -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]+))?$")); - - 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); -} -var locales = Object.keys(decimal); - -function toFloat(str) { - if (!isFloat(str)) return NaN; - return parseFloat(str); -} - -function toInt(str, radix) { - assertString(str); - return parseInt(str, radix || 10); -} - -function toBoolean(str, strict) { - assertString(str); - - if (strict) { - return str === '1' || /^true$/i.test(str); - } - - return str !== '0' && !/^false$/i.test(str) && str !== ''; -} - -function equals(str, comparison) { - assertString(str); - return str === comparison; -} - -function toString$1(input) { - if (_typeof(input) === 'object' && input !== null) { - if (typeof input.toString === 'function') { - input = input.toString(); - } else { - input = '[object Object]'; - } - } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) { - input = ''; - } - - return String(input); -} - -function merge() { - var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var defaults = arguments.length > 1 ? arguments[1] : undefined; - - for (var key in defaults) { - if (typeof obj[key] === 'undefined') { - obj[key] = defaults[key]; - } - } - - return obj; -} - -var defaulContainsOptions = { - ignoreCase: false -}; -function contains(str, elem, options) { - assertString(str); - options = merge(options, defaulContainsOptions); - return options.ignoreCase ? str.toLowerCase().indexOf(toString$1(elem).toLowerCase()) >= 0 : str.indexOf(toString$1(elem)) >= 0; -} - -function matches(str, pattern, modifiers) { - assertString(str); - - if (Object.prototype.toString.call(pattern) !== '[object RegExp]') { - pattern = new RegExp(pattern, modifiers); - } - - return pattern.test(str); -} - -/* eslint-disable prefer-rest-params */ - -function isByteLength(str, options) { - assertString(str); - var min; - var max; - - if (_typeof(options) === 'object') { - min = options.min || 0; - max = options.max; - } else { - // backwards compatibility: isByteLength(str, min [, max]) - min = arguments[1]; - max = arguments[2]; - } - - var len = encodeURI(str).split(/%..|./).length - 1; - return len >= min && (typeof max === 'undefined' || len <= max); -} - -var default_fqdn_options = { - require_tld: true, - allow_underscores: false, - allow_trailing_dot: false, - allow_numeric_tld: false -}; -function isFQDN(str, options) { - assertString(str); - options = merge(options, default_fqdn_options); - /* Remove the optional trailing dot before checking validity */ - - if (options.allow_trailing_dot && str[str.length - 1] === '.') { - str = str.substring(0, str.length - 1); - } - - var parts = str.split('.'); - var tld = parts[parts.length - 1]; - - if (options.require_tld) { - // disallow fqdns without tld - if (parts.length < 2) { - return false; - } - - if (!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) { - return false; - } // disallow spaces && special characers - - - if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) { - return false; - } - } // reject numeric TLDs - - - if (!options.allow_numeric_tld && /^\d+$/.test(tld)) { - return false; - } - - return parts.every(function (part) { - if (part.length > 63) { - return false; - } - - if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) { - return false; - } // disallow full-width chars - - - if (/[\uff01-\uff5e]/.test(part)) { - return false; - } // disallow parts starting or ending with hyphen - - - if (/^-|-$/.test(part)) { - return false; - } - - if (!options.allow_underscores && /_/.test(part)) { - return false; - } - - return true; - }); -} - -/** -11.3. Examples - - The following addresses - - fe80::1234 (on the 1st link of the node) - ff02::5678 (on the 5th link of the node) - ff08::9abc (on the 10th organization of the node) - - would be represented as follows: - - fe80::1234%1 - ff02::5678%5 - ff08::9abc%10 - - (Here we assume a natural translation from a zone index to the - part, where the Nth zone of any scope is translated into - "N".) - - If we use interface names as , those addresses could also be - represented as follows: - - fe80::1234%ne0 - ff02::5678%pvc1.3 - ff08::9abc%interface10 - - where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs - to the 5th link, and "interface10" belongs to the 10th organization. - * * */ - -var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; -var ipv6Block = /^[0-9A-F]{1,4}$/i; -function isIP(str) { - var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; - assertString(str); - version = String(version); - - if (!version) { - return isIP(str, 4) || isIP(str, 6); - } else if (version === '4') { - if (!ipv4Maybe.test(str)) { - return false; - } - - var parts = str.split('.').sort(function (a, b) { - return a - b; - }); - return parts[3] <= 255; - } else if (version === '6') { - var addressAndZone = [str]; // ipv6 addresses could have scoped architecture - // according to https://tools.ietf.org/html/rfc4007#section-11 - - if (str.includes('%')) { - addressAndZone = str.split('%'); - - if (addressAndZone.length !== 2) { - // it must be just two parts - return false; - } - - if (!addressAndZone[0].includes(':')) { - // the first part must be the address - return false; - } - - if (addressAndZone[1] === '') { - // the second part must not be empty - return false; - } - } - - var blocks = addressAndZone[0].split(':'); - var foundOmissionBlock = false; // marker to indicate :: - // At least some OS accept the last 32 bits of an IPv6 address - // (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says - // that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses, - // and '::a.b.c.d' is deprecated, but also valid. - - var foundIPv4TransitionBlock = isIP(blocks[blocks.length - 1], 4); - var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8; - - if (blocks.length > expectedNumberOfBlocks) { - return false; - } // initial or final :: - - - if (str === '::') { - return true; - } else if (str.substr(0, 2) === '::') { - blocks.shift(); - blocks.shift(); - foundOmissionBlock = true; - } else if (str.substr(str.length - 2) === '::') { - blocks.pop(); - blocks.pop(); - foundOmissionBlock = true; - } - - for (var i = 0; i < blocks.length; ++i) { - // test for a :: which can not be at the string start/end - // since those cases have been handled above - if (blocks[i] === '' && i > 0 && i < blocks.length - 1) { - if (foundOmissionBlock) { - return false; // multiple :: in address - } - - foundOmissionBlock = true; - } else if (foundIPv4TransitionBlock && i === blocks.length - 1) {// it has been checked before that the last - // block is a valid IPv4 address - } else if (!ipv6Block.test(blocks[i])) { - return false; - } - } - - if (foundOmissionBlock) { - return blocks.length >= 1; - } - - return blocks.length === expectedNumberOfBlocks; - } - - return false; -} - -var default_email_options = { - allow_display_name: false, - require_display_name: false, - allow_utf8_local_part: true, - require_tld: true, - blacklisted_chars: '', - ignore_max_length: false -}; -/* eslint-disable max-len */ - -/* eslint-disable no-control-regex */ - -var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)<(.+)>$/i; -var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i; -var gmailUserPart = /^[a-z\d]+$/; -var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i; -var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i; -var quotedEmailUserUtf8 = /^([\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 defaultMaxEmailLength = 254; -/* eslint-enable max-len */ - -/* eslint-enable no-control-regex */ - -/** - * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2 - * @param {String} display_name - */ - -function validateDisplayName(display_name) { - var trim_quotes = display_name.match(/^"(.+)"$/i); - var display_name_without_quotes = trim_quotes ? trim_quotes[1] : display_name; // display name with only spaces is not valid - - if (!display_name_without_quotes.trim()) { - return false; - } // check whether display name contains illegal character - - - var contains_illegal = /[\.";<>]/.test(display_name_without_quotes); - - if (contains_illegal) { - // if contains illegal characters, - // must to be enclosed in double-quotes, otherwise it's not a valid display name - if (!trim_quotes) { - return false; - } // the quotes in display name must start with character symbol \ - - - var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length; - - if (!all_start_with_back_slash) { - return false; - } - } - - return true; -} - -function isEmail(str, options) { - assertString(str); - options = merge(options, default_email_options); - - if (options.require_display_name || options.allow_display_name) { - var display_email = str.match(splitNameAddress); - - if (display_email) { - var display_name; - - var _display_email = _slicedToArray(display_email, 3); - - display_name = _display_email[1]; - str = _display_email[2]; - - // sometimes need to trim the last space to get the display name - // because there may be a space between display name and email address - // eg. myname - // the display name is `myname` instead of `myname `, so need to trim the last space - if (display_name.endsWith(' ')) { - display_name = display_name.substr(0, display_name.length - 1); - } - - if (!validateDisplayName(display_name)) { - return false; - } - } else if (options.require_display_name) { - return false; - } - } - - if (!options.ignore_max_length && str.length > defaultMaxEmailLength) { - return false; - } - - var parts = str.split('@'); - var domain = parts.pop(); - var user = parts.join('@'); - var lower_domain = domain.toLowerCase(); - - if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) { - /* - Previously we removed dots for gmail addresses before validating. - This was removed because it allows `multiple..dots@gmail.com` - to be reported as valid, but it is not. - Gmail only normalizes single dots, removing them from here is pointless, - should be done in normalizeEmail - */ - user = user.toLowerCase(); // Removing sub-address from username before gmail validation - - var username = user.split('+')[0]; // Dots are not included in gmail length restriction - - if (!isByteLength(username.replace('.', ''), { - min: 6, - max: 30 - })) { - return false; - } - - var _user_parts = username.split('.'); - - for (var i = 0; i < _user_parts.length; i++) { - if (!gmailUserPart.test(_user_parts[i])) { - return false; - } - } - } - - if (options.ignore_max_length === false && (!isByteLength(user, { - max: 64 - }) || !isByteLength(domain, { - max: 254 - }))) { - return false; - } - - if (!isFQDN(domain, { - require_tld: options.require_tld - })) { - if (!options.allow_ip_domain) { - return false; - } - - if (!isIP(domain)) { - if (!domain.startsWith('[') || !domain.endsWith(']')) { - return false; - } - - var noBracketdomain = domain.substr(1, domain.length - 2); - - if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) { - return false; - } - } - } - - if (user[0] === '"') { - user = user.slice(1, user.length - 1); - return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user); - } - - var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart; - var user_parts = user.split('.'); - - for (var _i = 0; _i < user_parts.length; _i++) { - if (!pattern.test(user_parts[_i])) { - return false; - } - } - - if (options.blacklisted_chars) { - if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false; - } - - return true; -} - -/* -options for isURL method - -require_protocol - if set as true isURL will return false if protocol is not present in the URL -require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option -protocols - valid protocols can be modified with this option -require_host - if set as false isURL will not check if host is present in the URL -require_port - if set as true isURL will check if port is present in the URL -allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed -validate_length - if set as false isURL will skip string length validation (IE maximum is 2083) - -*/ - -var default_url_options = { - protocols: ['http', 'https', 'ftp'], - require_tld: true, - require_protocol: false, - require_host: true, - require_port: false, - require_valid_protocol: true, - allow_underscores: false, - allow_trailing_dot: false, - allow_protocol_relative_urls: false, - validate_length: true -}; -var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/; - -function isRegExp(obj) { - return Object.prototype.toString.call(obj) === '[object RegExp]'; -} - -function checkHost(host, matches) { - for (var i = 0; i < matches.length; i++) { - var match = matches[i]; - - if (host === match || isRegExp(match) && match.test(host)) { - return true; - } - } - - return false; -} - -function isURL(url, options) { - assertString(url); - - if (!url || /[\s<>]/.test(url)) { - return false; - } - - if (url.indexOf('mailto:') === 0) { - return false; - } - - options = merge(options, default_url_options); - - if (options.validate_length && url.length >= 2083) { - return false; - } - - var protocol, auth, host, hostname, port, port_str, split, ipv6; - split = url.split('#'); - url = split.shift(); - split = url.split('?'); - url = split.shift(); - split = url.split('://'); - - if (split.length > 1) { - protocol = split.shift().toLowerCase(); - - if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) { - return false; - } - } else if (options.require_protocol) { - return false; - } else if (url.substr(0, 2) === '//') { - if (!options.allow_protocol_relative_urls) { - return false; - } - - split[0] = url.substr(2); - } - - url = split.join('://'); - - if (url === '') { - return false; - } - - split = url.split('/'); - url = split.shift(); - - if (url === '' && !options.require_host) { - return true; - } - - split = url.split('@'); - - if (split.length > 1) { - if (options.disallow_auth) { - return false; - } - - auth = split.shift(); - - if (auth.indexOf(':') === -1 || auth.indexOf(':') >= 0 && auth.split(':').length > 2) { - return false; - } - } - - hostname = split.join('@'); - port_str = null; - ipv6 = null; - var ipv6_match = hostname.match(wrapped_ipv6); - - if (ipv6_match) { - host = ''; - ipv6 = ipv6_match[1]; - port_str = ipv6_match[2] || null; - } else { - split = hostname.split(':'); - host = split.shift(); - - if (split.length) { - port_str = split.join(':'); - } - } - - if (port_str !== null) { - port = parseInt(port_str, 10); - - if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) { - return false; - } - } else if (options.require_port) { - return false; - } - - if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) { - return false; - } - - host = host || ipv6; - - if (options.host_whitelist && !checkHost(host, options.host_whitelist)) { - return false; - } - - if (options.host_blacklist && checkHost(host, options.host_blacklist)) { - return false; - } - - return true; -} - -var macAddress = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/; -var macAddressNoColons = /^([0-9a-fA-F]){12}$/; -var macAddressWithHyphen = /^([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])$/; -var macAddressWithSpaces = /^([0-9a-fA-F][0-9a-fA-F]\s){5}([0-9a-fA-F][0-9a-fA-F])$/; -var macAddressWithDots = /^([0-9a-fA-F]{4}).([0-9a-fA-F]{4}).([0-9a-fA-F]{4})$/; -function isMACAddress(str, options) { - assertString(str); - - if (options && options.no_colons) { - return macAddressNoColons.test(str); - } - - return macAddress.test(str) || macAddressWithHyphen.test(str) || macAddressWithSpaces.test(str) || macAddressWithDots.test(str); -} - -var subnetMaybe = /^\d{1,2}$/; -function isIPRange(str) { - assertString(str); - var parts = str.split('/'); // parts[0] -> ip, parts[1] -> subnet - - if (parts.length !== 2) { - return false; - } - - if (!subnetMaybe.test(parts[1])) { - return false; - } // Disallow preceding 0 i.e. 01, 02, ... - - - if (parts[1].length > 1 && parts[1].startsWith('0')) { - return false; - } - - return isIP(parts[0], 4) && parts[1] <= 32 && parts[1] >= 0; -} - -var default_date_options = { - format: 'YYYY/MM/DD', - delimiters: ['/', '-'], - strictMode: false -}; - -function isValidFormat(format) { - return /(^(y{4}|y{2})[\/-](m{1,2})[\/-](d{1,2})$)|(^(m{1,2})[\/-](d{1,2})[\/-]((y{4}|y{2})$))|(^(d{1,2})[\/-](m{1,2})[\/-]((y{4}|y{2})$))/gi.test(format); -} - -function zip(date, format) { - var zippedArr = [], - len = Math.min(date.length, format.length); - - for (var i = 0; i < len; i++) { - zippedArr.push([date[i], format[i]]); - } - - return zippedArr; -} - -function isDate(input, options) { - if (typeof options === 'string') { - // Allow backward compatbility for old format isDate(input [, format]) - options = merge({ - format: options - }, default_date_options); - } else { - options = merge(options, default_date_options); - } - - if (typeof input === 'string' && isValidFormat(options.format)) { - var formatDelimiter = options.delimiters.find(function (delimiter) { - return options.format.indexOf(delimiter) !== -1; - }); - var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) { - return input.indexOf(delimiter) !== -1; - }); - var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter)); - var dateObj = {}; - - var _iterator = _createForOfIteratorHelper(dateAndFormat), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var _step$value = _slicedToArray(_step.value, 2), - dateWord = _step$value[0], - formatWord = _step$value[1]; - - if (dateWord.length !== formatWord.length) { - return false; - } - - dateObj[formatWord.charAt(0)] = dateWord; - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - - return new Date("".concat(dateObj.m, "/").concat(dateObj.d, "/").concat(dateObj.y)).getDate() === +dateObj.d; - } - - if (!options.strictMode) { - return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input); - } - - return false; -} - -function isBoolean(str) { - assertString(str); - return ['true', 'false', '1', '0'].indexOf(str) >= 0; -} - -var localeReg = /^[A-z]{2,4}([_-]([A-z]{4}|[\d]{3}))?([_-]([A-z]{2}|[\d]{3}))?$/; -function isLocale(str) { - assertString(str); - - if (str === 'en_US_POSIX' || str === 'ca_ES_VALENCIA') { - return true; - } - - return localeReg.test(str); -} - -function isAlpha(_str) { - var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US'; - var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - assertString(_str); - var str = _str; - var ignore = options.ignore; - - if (ignore) { - if (ignore instanceof RegExp) { - str = str.replace(ignore, ''); - } else if (typeof ignore === 'string') { - str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore - } else { - throw new Error('ignore should be instance of a String or RegExp'); - } - } - - if (locale in alpha) { - return alpha[locale].test(str); - } - - throw new Error("Invalid locale '".concat(locale, "'")); -} -var locales$1 = Object.keys(alpha); - -function isAlphanumeric(str) { - var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US'; - assertString(str); - - if (locale in alphanumeric) { - return alphanumeric[locale].test(str); - } - - throw new Error("Invalid locale '".concat(locale, "'")); -} -var locales$2 = Object.keys(alphanumeric); - -var numericNoSymbols = /^[0-9]+$/; -function isNumeric(str, options) { - assertString(str); - - if (options && options.no_symbols) { - return numericNoSymbols.test(str); - } - - return new RegExp("^[+-]?([0-9]*[".concat((options || {}).locale ? decimal[options.locale] : '.', "])?[0-9]+$")).test(str); -} - -/** - * Reference: - * https://en.wikipedia.org/ -- Wikipedia - * https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number - * https://countrycode.org/ -- Country Codes - */ - -var passportRegexByCountryCode = { - AM: /^[A-Z]{2}\d{7}$/, - // ARMENIA - AR: /^[A-Z]{3}\d{6}$/, - // ARGENTINA - AT: /^[A-Z]\d{7}$/, - // AUSTRIA - AU: /^[A-Z]\d{7}$/, - // AUSTRALIA - BE: /^[A-Z]{2}\d{6}$/, - // BELGIUM - BG: /^\d{9}$/, - // BULGARIA - BY: /^[A-Z]{2}\d{7}$/, - // BELARUS - CA: /^[A-Z]{2}\d{6}$/, - // CANADA - CH: /^[A-Z]\d{7}$/, - // SWITZERLAND - CN: /^[GE]\d{8}$/, - // CHINA [G=Ordinary, E=Electronic] followed by 8-digits - CY: /^[A-Z](\d{6}|\d{8})$/, - // CYPRUS - CZ: /^\d{8}$/, - // CZECH REPUBLIC - DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/, - // GERMANY - DK: /^\d{9}$/, - // DENMARK - DZ: /^\d{9}$/, - // ALGERIA - EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/, - // ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits - ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/, - // SPAIN - FI: /^[A-Z]{2}\d{7}$/, - // FINLAND - FR: /^\d{2}[A-Z]{2}\d{5}$/, - // FRANCE - GB: /^\d{9}$/, - // UNITED KINGDOM - GR: /^[A-Z]{2}\d{7}$/, - // GREECE - HR: /^\d{9}$/, - // CROATIA - HU: /^[A-Z]{2}(\d{6}|\d{7})$/, - // HUNGARY - IE: /^[A-Z0-9]{2}\d{7}$/, - // IRELAND - IN: /^[A-Z]{1}-?\d{7}$/, - // INDIA - IS: /^(A)\d{7}$/, - // ICELAND - IT: /^[A-Z0-9]{2}\d{7}$/, - // ITALY - JP: /^[A-Z]{2}\d{7}$/, - // JAPAN - KR: /^[MS]\d{8}$/, - // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports] - LT: /^[A-Z0-9]{8}$/, - // LITHUANIA - LU: /^[A-Z0-9]{8}$/, - // LUXEMBURG - LV: /^[A-Z0-9]{2}\d{7}$/, - // LATVIA - MT: /^\d{7}$/, - // MALTA - NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, - // NETHERLANDS - PO: /^[A-Z]{2}\d{7}$/, - // POLAND - PT: /^[A-Z]\d{6}$/, - // PORTUGAL - RO: /^\d{8,9}$/, - // ROMANIA - RU: /^\d{2}\d{2}\d{6}$/, - // RUSSIAN FEDERATION - SE: /^\d{8}$/, - // SWEDEN - SL: /^(P)[A-Z]\d{7}$/, - // SLOVANIA - SK: /^[0-9A-Z]\d{7}$/, - // SLOVAKIA - TR: /^[A-Z]\d{8}$/, - // TURKEY - UA: /^[A-Z]{2}\d{6}$/, - // UKRAINE - US: /^\d{9}$/ // UNITED STATES - -}; -/** - * Check if str is a valid passport number - * relative to provided ISO Country Code. - * - * @param {string} str - * @param {string} countryCode - * @return {boolean} - */ - -function isPassportNumber(str, countryCode) { - assertString(str); - /** Remove All Whitespaces, Convert to UPPERCASE */ - - var normalizedStr = str.replace(/\s/g, '').toUpperCase(); - return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr); -} - -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 minCheckPassed = !options.hasOwnProperty('min') || str >= options.min; - var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max; - var ltCheckPassed = !options.hasOwnProperty('lt') || str < options.lt; - var gtCheckPassed = !options.hasOwnProperty('gt') || str > options.gt; - return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed; -} - -function isPort(str) { - return isInt(str, { - min: 0, - max: 65535 - }); -} - -function isLowercase(str) { - assertString(str); - return str === str.toLowerCase(); -} - -function isUppercase(str) { - assertString(str); - return str === str.toUpperCase(); -} - -var imeiRegexWithoutHypens = /^[0-9]{15}$/; -var imeiRegexWithHypens = /^\d{2}-\d{6}-\d{6}-\d{1}$/; -function isIMEI(str, options) { - assertString(str); - options = options || {}; // default regex for checking imei is the one without hyphens - - var imeiRegex = imeiRegexWithoutHypens; - - if (options.allow_hyphens) { - imeiRegex = imeiRegexWithHypens; - } - - if (!imeiRegex.test(str)) { - return false; - } - - str = str.replace(/-/g, ''); - var sum = 0, - mul = 2, - l = 14; - - for (var i = 0; i < l; i++) { - var digit = str.substring(l - i - 1, l - i); - var tp = parseInt(digit, 10) * mul; - - if (tp >= 10) { - sum += tp % 10 + 1; - } else { - sum += tp; - } - - if (mul === 1) { - mul += 1; - } else { - mul -= 1; - } - } - - var chk = (10 - sum % 10) % 10; - - if (chk !== parseInt(str.substring(14, 15), 10)) { - return false; - } - - return true; -} - -/* eslint-disable no-control-regex */ - -var ascii = /^[\x00-\x7F]+$/; -/* eslint-enable no-control-regex */ - -function isAscii(str) { - assertString(str); - return ascii.test(str); -} - -var fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/; -function isFullWidth(str) { - assertString(str); - return fullWidth.test(str); -} - -var halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/; -function isHalfWidth(str) { - assertString(str); - return halfWidth.test(str); -} - -function isVariableWidth(str) { - assertString(str); - return fullWidth.test(str) && halfWidth.test(str); -} - -/* eslint-disable no-control-regex */ - -var multibyte = /[^\x00-\x7F]/; -/* eslint-enable no-control-regex */ - -function isMultibyte(str) { - assertString(str); - return multibyte.test(str); -} - -/** - * Build RegExp object from an array - * of multiple/multi-line regexp parts - * - * @param {string[]} parts - * @param {string} flags - * @return {object} - RegExp object - */ -function multilineRegexp(parts, flags) { - var regexpAsStringLiteral = parts.join(''); - return new RegExp(regexpAsStringLiteral, flags); -} - -/** - * Regular Expression to match - * semantic versioning (SemVer) - * built from multi-line, multi-parts regexp - * Reference: https://semver.org/ - */ - -var semanticVersioningRegex = multilineRegexp(['^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)', '(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))', '?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$'], 'i'); -function isSemVer(str) { - assertString(str); - return semanticVersioningRegex.test(str); -} - -var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/; -function isSurrogatePair(str) { - assertString(str); - return surrogatePair.test(str); -} - -var includes = function includes(arr, val) { - return arr.some(function (arrVal) { - return val === arrVal; - }); -}; - -function decimalRegExp(options) { - var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$")); - return regExp; -} - -var default_decimal_options = { - force_decimal: false, - decimal_digits: '1,', - locale: 'en-US' -}; -var blacklist = ['', '-', '+']; -function isDecimal(str, options) { - assertString(str); - options = merge(options, default_decimal_options); - - if (options.locale in decimal) { - return !includes(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str); - } - - throw new Error("Invalid locale '".concat(options.locale, "'")); -} - -var hexadecimal = /^(0x|0h)?[0-9A-F]+$/i; -function isHexadecimal(str) { - assertString(str); - return hexadecimal.test(str); -} - -var octal = /^(0o)?[0-7]+$/i; -function isOctal(str) { - assertString(str); - return octal.test(str); -} - -function isDivisibleBy(str, num) { - assertString(str); - return toFloat(str) % parseInt(num, 10) === 0; -} - -var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i; -function isHexColor(str) { - assertString(str); - return hexcolor.test(str); -} - -var rgbColor = /^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/; -var rgbaColor = /^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/; -var rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/; -var rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/; -function isRgbColor(str) { - var includePercentValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - assertString(str); - - if (!includePercentValues) { - return rgbColor.test(str) || rgbaColor.test(str); - } - - return rgbColor.test(str) || rgbaColor.test(str) || rgbColorPercent.test(str) || rgbaColorPercent.test(str); -} - -var hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; -var hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; -function isHSL(str) { - assertString(str); - return hslcomma.test(str) || hslspace.test(str); -} - -var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/; -function isISRC(str) { - assertString(str); - return isrc.test(str); -} - -/** - * List of country codes with - * corresponding IBAN regular expression - * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number - */ - -var ibanRegexThroughCountryCode = { - AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/, - AE: /^(AE[0-9]{2})\d{3}\d{16}$/, - AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/, - AT: /^(AT[0-9]{2})\d{16}$/, - AZ: /^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/, - BA: /^(BA[0-9]{2})\d{16}$/, - BE: /^(BE[0-9]{2})\d{12}$/, - BG: /^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/, - BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/, - BR: /^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/, - BY: /^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/, - CH: /^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/, - CR: /^(CR[0-9]{2})\d{18}$/, - 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}$/, - DO: /^(DO[0-9]{2})[A-Z]{4}\d{20}$/, - EE: /^(EE[0-9]{2})\d{16}$/, - EG: /^(EG[0-9]{2})\d{25}$/, - ES: /^(ES[0-9]{2})\d{20}$/, - FI: /^(FI[0-9]{2})\d{14}$/, - FO: /^(FO[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-Z0-9]{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}$/, - GT: /^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/, - HR: /^(HR[0-9]{2})\d{17}$/, - HU: /^(HU[0-9]{2})\d{24}$/, - IE: /^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/, - IL: /^(IL[0-9]{2})\d{19}$/, - IQ: /^(IQ[0-9]{2})[A-Z]{4}\d{15}$/, - IR: /^(IR[0-9]{2})0\d{2}0\d{18}$/, - IS: /^(IS[0-9]{2})\d{22}$/, - IT: /^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/, - JO: /^(JO[0-9]{2})[A-Z]{4}\d{22}$/, - 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}$/, - LC: /^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/, - 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-Z0-9]{20}$/, - ME: /^(ME[0-9]{2})\d{18}$/, - MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/, - MR: /^(MR[0-9]{2})\d{23}$/, - MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/, - MU: /^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/, - NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/, - NO: /^(NO[0-9]{2})\d{11}$/, - PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/, - PL: /^(PL[0-9]{2})\d{24}$/, - PS: /^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/, - RS: /^(RS[0-9]{2})\d{18}$/, - SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/, - SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/, - 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}$/, - SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/, - TL: /^(TL[0-9]{2})\d{19}$/, - 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}$/, - VA: /^(VA[0-9]{2})\d{18}$/, - VG: /^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/, - XK: /^(XK[0-9]{2})\d{16}$/ -}; -/** - * Check whether string has correct universal IBAN format - * The IBAN consists of up to 34 alphanumeric characters, as follows: - * Country Code using ISO 3166-1 alpha-2, two letters - * check digits, two digits and - * Basic Bank Account Number (BBAN), up to 30 alphanumeric characters. - * NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z] - * - * @param {string} str - string under validation - * @return {boolean} - */ - -function hasValidIbanFormat(str) { - // Strip white spaces and hyphens - var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase(); - var isoCountryCode = strippedStr.slice(0, 2).toUpperCase(); - return isoCountryCode in ibanRegexThroughCountryCode && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr); -} -/** - * Check whether string has valid IBAN Checksum - * by performing basic mod-97 operation and - * the remainder should equal 1 - * -- Start by rearranging the IBAN by moving the four initial characters to the end of the string - * -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35 - * -- Interpret the string as a decimal integer and - * -- compute the remainder on division by 97 (mod 97) - * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number - * - * @param {string} str - * @return {boolean} - */ - - -function hasValidIbanChecksum(str) { - var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic - - var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4); - var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (_char) { - return _char.charCodeAt(0) - 55; - }); - var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) { - return Number(acc + value) % 97; - }, ''); - return remainder === 1; -} - -function isIBAN(str) { - assertString(str); - return hasValidIbanFormat(str) && hasValidIbanChecksum(str); -} - -var isBICReg = /^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/; -function isBIC(str) { - assertString(str); - return isBICReg.test(str); -} - -var md5 = /^[a-f0-9]{32}$/; -function isMD5(str) { - assertString(str); - return md5.test(str); -} - -var lengths = { - 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 -}; -function isHash(str, algorithm) { - assertString(str); - var hash = new RegExp("^[a-fA-F0-9]{".concat(lengths[algorithm], "}$")); - return hash.test(str); -} - -var notBase64 = /[^A-Z0-9+\/=]/i; -var urlSafeBase64 = /^[A-Z0-9_\-]*$/i; -var defaultBase64Options = { - urlSafe: false -}; -function isBase64(str, options) { - assertString(str); - options = merge(options, defaultBase64Options); - var len = str.length; - - if (options.urlSafe) { - return urlSafeBase64.test(str); - } - - if (len % 4 !== 0 || notBase64.test(str)) { - return false; - } - - var firstPaddingChar = str.indexOf('='); - return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '='; -} - -function isJWT(str) { - assertString(str); - var dotSplit = str.split('.'); - var len = dotSplit.length; - - if (len > 3 || len < 2) { - return false; - } - - return dotSplit.reduce(function (acc, currElem) { - return acc && isBase64(currElem, { - urlSafe: true - }); - }, true); -} - -var default_json_options = { - allow_primitives: false -}; -function isJSON(str, options) { - assertString(str); - - try { - options = merge(options, default_json_options); - var primitives = []; - - if (options.allow_primitives) { - primitives = [null, false, true]; - } - - var obj = JSON.parse(str); - return primitives.includes(obj) || !!obj && _typeof(obj) === 'object'; - } catch (e) { - /* ignore */ - } - - return false; -} - -var default_is_empty_options = { - ignore_whitespace: false -}; -function isEmpty(str, options) { - assertString(str); - options = merge(options, default_is_empty_options); - return (options.ignore_whitespace ? str.trim().length : str.length) === 0; -} - -/* eslint-disable prefer-rest-params */ - -function isLength(str, options) { - assertString(str); - var min; - var max; - - if (_typeof(options) === 'object') { - min = options.min || 0; - max = options.max; - } else { - // backwards compatibility: isLength(str, min [, max]) - min = arguments[1] || 0; - max = arguments[2]; - } - - var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; - var len = str.length - surrogatePairs.length; - return len >= min && (typeof max === 'undefined' || len <= max); -} - -var uuid = { - 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 -}; -function isUUID(str) { - var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all'; - assertString(str); - var pattern = uuid[version]; - return pattern && pattern.test(str); -} - -function isMongoId(str) { - assertString(str); - return isHexadecimal(str) && str.length === 24; -} - -function isAfter(str) { - var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date()); - assertString(str); - var comparison = toDate(date); - var original = toDate(str); - return !!(original && comparison && original > comparison); -} - -function isBefore(str) { - var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date()); - assertString(str); - var comparison = toDate(date); - var original = toDate(str); - return !!(original && comparison && original < comparison); -} - -function isIn(str, options) { - assertString(str); - var i; - - if (Object.prototype.toString.call(options) === '[object Array]') { - var array = []; - - for (i in options) { - // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes - // istanbul ignore else - if ({}.hasOwnProperty.call(options, i)) { - array[i] = toString$1(options[i]); - } - } - - return array.indexOf(str) >= 0; - } else if (_typeof(options) === 'object') { - return options.hasOwnProperty(str); - } else if (options && typeof options.indexOf === 'function') { - return options.indexOf(str) >= 0; - } - - return false; -} - -/* eslint-disable max-len */ - -var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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})$/; -/* eslint-enable max-len */ - -function isCreditCard(str) { - assertString(str); - var sanitized = str.replace(/[- ]+/g, ''); - - if (!creditCard.test(sanitized)) { - return false; - } - - var sum = 0; - var digit; - var tmpNum; - var shouldDouble; - - for (var i = sanitized.length - 1; i >= 0; i--) { - digit = sanitized.substring(i, i + 1); - tmpNum = parseInt(digit, 10); - - if (shouldDouble) { - tmpNum *= 2; - - if (tmpNum >= 10) { - sum += tmpNum % 10 + 1; - } else { - sum += tmpNum; - } - } else { - sum += tmpNum; - } - - shouldDouble = !shouldDouble; - } - - return !!(sum % 10 === 0 ? sanitized : false); -} - -var validators = { - ES: function ES(str) { - assertString(str); - var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/; - var charsValue = { - X: 0, - Y: 1, - Z: 2 - }; - var controlDigits = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E']; // sanitize user input - - var sanitized = str.trim().toUpperCase(); // validate the data structure - - if (!DNI.test(sanitized)) { - return false; - } // validate the control digit - - - var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) { - return charsValue[_char]; - }); - return sanitized.endsWith(controlDigits[number % 23]); - }, - IN: function IN(str) { - var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/; // multiplication table - - var d = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]; // permutation table - - var p = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]]; // sanitize user input - - var sanitized = str.trim(); // validate the data structure - - if (!DNI.test(sanitized)) { - return false; - } - - var c = 0; - var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse(); - invertedArray.forEach(function (val, i) { - c = d[c][p[i % 8][val]]; - }); - return c === 0; - }, - IT: function IT(str) { - if (str.length !== 9) return false; - if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana - - return str.search(/C[A-Z][0-9]{5}[A-Z]{2}/i) > -1; - }, - NO: function NO(str) { - var sanitized = str.trim(); - if (isNaN(Number(sanitized))) return false; - if (sanitized.length !== 11) return false; - if (sanitized === '00000000000') return false; // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer - - var f = sanitized.split('').map(Number); - var k1 = (11 - (3 * f[0] + 7 * f[1] + 6 * f[2] + 1 * f[3] + 8 * f[4] + 9 * f[5] + 4 * f[6] + 5 * f[7] + 2 * f[8]) % 11) % 11; - var k2 = (11 - (5 * f[0] + 4 * f[1] + 3 * f[2] + 2 * f[3] + 7 * f[4] + 6 * f[5] + 5 * f[6] + 4 * f[7] + 3 * f[8] + 2 * k1) % 11) % 11; - if (k1 !== f[9] || k2 !== f[10]) return false; - return true; - }, - 'he-IL': function heIL(str) { - var DNI = /^\d{9}$/; // sanitize user input - - var sanitized = str.trim(); // validate the data structure - - if (!DNI.test(sanitized)) { - return false; - } - - var id = sanitized; - var sum = 0, - incNum; - - for (var i = 0; i < id.length; i++) { - incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2 - - sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total - } - - return sum % 10 === 0; - }, - 'ar-TN': function arTN(str) { - var DNI = /^\d{8}$/; // sanitize user input - - var sanitized = str.trim(); // validate the data structure - - if (!DNI.test(sanitized)) { - return false; - } - - return true; - }, - 'zh-CN': function zhCN(str) { - var provincesAndCities = ['11', // 北京 - '12', // 天津 - '13', // 河北 - '14', // 山西 - '15', // 内蒙古 - '21', // 辽宁 - '22', // 吉林 - '23', // 黑龙江 - '31', // 上海 - '32', // 江苏 - '33', // 浙江 - '34', // 安徽 - '35', // 福建 - '36', // 江西 - '37', // 山东 - '41', // 河南 - '42', // 湖北 - '43', // 湖南 - '44', // 广东 - '45', // 广西 - '46', // 海南 - '50', // 重庆 - '51', // 四川 - '52', // 贵州 - '53', // 云南 - '54', // 西藏 - '61', // 陕西 - '62', // 甘肃 - '63', // 青海 - '64', // 宁夏 - '65', // 新疆 - '71', // 台湾 - '81', // 香港 - '82', // 澳门 - '91' // 国外 - ]; - var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2']; - var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; - - var checkAddressCode = function checkAddressCode(addressCode) { - return provincesAndCities.includes(addressCode); - }; - - var checkBirthDayCode = function checkBirthDayCode(birDayCode) { - var yyyy = parseInt(birDayCode.substring(0, 4), 10); - var mm = parseInt(birDayCode.substring(4, 6), 10); - var dd = parseInt(birDayCode.substring(6), 10); - var xdata = new Date(yyyy, mm - 1, dd); - - if (xdata > new Date()) { - return false; // eslint-disable-next-line max-len - } else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) { - return true; - } - - return false; - }; - - var getParityBit = function getParityBit(idCardNo) { - var id17 = idCardNo.substring(0, 17); - var power = 0; - - for (var i = 0; i < 17; i++) { - power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10); - } - - var mod = power % 11; - return parityBit[mod]; - }; - - var checkParityBit = function checkParityBit(idCardNo) { - return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase(); - }; - - var check15IdCardNo = function check15IdCardNo(idCardNo) { - var check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo); - if (!check) return false; - var addressCode = idCardNo.substring(0, 2); - check = checkAddressCode(addressCode); - if (!check) return false; - var birDayCode = "19".concat(idCardNo.substring(6, 12)); - check = checkBirthDayCode(birDayCode); - if (!check) return false; - return true; - }; - - var check18IdCardNo = function check18IdCardNo(idCardNo) { - var check = /^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(idCardNo); - if (!check) return false; - var addressCode = idCardNo.substring(0, 2); - check = checkAddressCode(addressCode); - if (!check) return false; - var birDayCode = idCardNo.substring(6, 14); - check = checkBirthDayCode(birDayCode); - if (!check) return false; - return checkParityBit(idCardNo); - }; - - var checkIdCardNo = function checkIdCardNo(idCardNo) { - var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo); - if (!check) return false; - - if (idCardNo.length === 15) { - return check15IdCardNo(idCardNo); - } - - return check18IdCardNo(idCardNo); - }; - - return checkIdCardNo(str); - }, - 'zh-TW': function zhTW(str) { - var ALPHABET_CODES = { - A: 10, - B: 11, - C: 12, - D: 13, - E: 14, - F: 15, - G: 16, - H: 17, - I: 34, - J: 18, - K: 19, - L: 20, - M: 21, - N: 22, - O: 35, - P: 23, - Q: 24, - R: 25, - S: 26, - T: 27, - U: 28, - V: 29, - W: 32, - X: 30, - Y: 31, - Z: 33 - }; - var sanitized = str.trim().toUpperCase(); - if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false; - return Array.from(sanitized).reduce(function (sum, number, index) { - if (index === 0) { - var code = ALPHABET_CODES[number]; - return code % 10 * 9 + Math.floor(code / 10); - } - - if (index === 9) { - return (10 - sum % 10 - Number(number)) % 10 === 0; - } - - return sum + Number(number) * (9 - index); - }, 0); - } -}; -function isIdentityCard(str, locale) { - assertString(str); - - if (locale in validators) { - return validators[locale](str); - } else if (locale === 'any') { - for (var key in validators) { - // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes - // istanbul ignore else - if (validators.hasOwnProperty(key)) { - var validator = validators[key]; - - if (validator(str)) { - return true; - } - } - } - - return false; - } - - throw new Error("Invalid locale '".concat(locale, "'")); -} - -/** - * The most commonly used EAN standard is - * the thirteen-digit EAN-13, while the - * less commonly used 8-digit EAN-8 barcode was - * introduced for use on small packages. - * EAN consists of: - * GS1 prefix, manufacturer code, product code and check digit - * Reference: https://en.wikipedia.org/wiki/International_Article_Number - */ -/** - * Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13 - * and Regular Expression for valid EANs (EAN-8, EAN-13), - * with exact numberic matching of 8 or 13 digits [0-9] - */ - -var LENGTH_EAN_8 = 8; -var validEanRegex = /^(\d{8}|\d{13})$/; -/** - * Get position weight given: - * EAN length and digit index/position - * - * @param {number} length - * @param {number} index - * @return {number} - */ - -function getPositionWeightThroughLengthAndIndex(length, index) { - if (length === LENGTH_EAN_8) { - return index % 2 === 0 ? 3 : 1; - } - - return index % 2 === 0 ? 1 : 3; -} -/** - * Calculate EAN Check Digit - * Reference: https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit - * - * @param {string} ean - * @return {number} - */ - - -function calculateCheckDigit(ean) { - var checksum = ean.slice(0, -1).split('').map(function (_char, index) { - return Number(_char) * getPositionWeightThroughLengthAndIndex(ean.length, index); - }).reduce(function (acc, partialSum) { - return acc + partialSum; - }, 0); - var remainder = 10 - checksum % 10; - return remainder < 10 ? remainder : 0; -} -/** - * Check if string is valid EAN: - * Matches EAN-8/EAN-13 regex - * Has valid check digit. - * - * @param {string} str - * @return {boolean} - */ - - -function isEAN(str) { - assertString(str); - var actualCheckDigit = Number(str.slice(-1)); - return validEanRegex.test(str) && actualCheckDigit === calculateCheckDigit(str); -} - -var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/; -function isISIN(str) { - assertString(str); - - if (!isin.test(str)) { - return false; - } - - var checksumStr = str.replace(/[A-Z]/g, function (character) { - return parseInt(character, 36); - }); - var sum = 0; - var digit; - var tmpNum; - var shouldDouble = true; - - for (var i = checksumStr.length - 2; i >= 0; i--) { - digit = checksumStr.substring(i, i + 1); - tmpNum = parseInt(digit, 10); - - if (shouldDouble) { - tmpNum *= 2; - - if (tmpNum >= 10) { - sum += tmpNum + 1; - } else { - sum += tmpNum; - } - } else { - sum += tmpNum; - } - - shouldDouble = !shouldDouble; - } - - return parseInt(str.substr(str.length - 1), 10) === (10000 - sum) % 10; -} - -var isbn10Maybe = /^(?:[0-9]{9}X|[0-9]{10})$/; -var isbn13Maybe = /^(?:[0-9]{13})$/; -var factor = [1, 3]; -function isISBN(str) { - var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; - assertString(str); - version = String(version); - - if (!version) { - return isISBN(str, 10) || isISBN(str, 13); - } - - var sanitized = str.replace(/[\s-]+/g, ''); - var checksum = 0; - var i; - - if (version === '10') { - if (!isbn10Maybe.test(sanitized)) { - return false; - } - - for (i = 0; i < 9; i++) { - checksum += (i + 1) * sanitized.charAt(i); - } - - if (sanitized.charAt(9) === 'X') { - checksum += 10 * 10; - } else { - checksum += 10 * sanitized.charAt(9); - } - - if (checksum % 11 === 0) { - return !!sanitized; - } - } else if (version === '13') { - if (!isbn13Maybe.test(sanitized)) { - return false; - } - - for (i = 0; i < 12; i++) { - checksum += factor[i % 2] * sanitized.charAt(i); - } - - if (sanitized.charAt(12) - (10 - checksum % 10) % 10 === 0) { - return !!sanitized; - } - } - - return false; -} - -var issn = '^\\d{4}-?\\d{3}[\\dX]$'; -function isISSN(str) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - assertString(str); - var testIssn = issn; - testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn; - testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i'); - - if (!testIssn.test(str)) { - return false; - } - - var digits = str.replace('-', '').toUpperCase(); - var checksum = 0; - - for (var i = 0; i < digits.length; i++) { - var digit = digits[i]; - checksum += (digit === 'X' ? 10 : +digit) * (8 - i); - } - - return checksum % 11 === 0; -} - -/** - * Algorithmic validation functions - * May be used as is or implemented in the workflow of other validators. - */ - -/* - * ISO 7064 validation function - * Called with a string of numbers (incl. check digit) - * to validate according to ISO 7064 (MOD 11, 10). - */ -function iso7064Check(str) { - var checkvalue = 10; - - for (var i = 0; i < str.length - 1; i++) { - checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? 10 * 2 % 11 : (parseInt(str[i], 10) + checkvalue) % 10 * 2 % 11; - } - - checkvalue = checkvalue === 1 ? 0 : 11 - checkvalue; - return checkvalue === parseInt(str[10], 10); -} -/* - * Luhn (mod 10) validation function - * Called with a string of numbers (incl. check digit) - * to validate according to the Luhn algorithm. - */ - -function luhnCheck(str) { - var checksum = 0; - var second = false; - - for (var i = str.length - 1; i >= 0; i--) { - if (second) { - var product = parseInt(str[i], 10) * 2; - - if (product > 9) { - // sum digits of product and add to checksum - checksum += product.toString().split('').map(function (a) { - return parseInt(a, 10); - }).reduce(function (a, b) { - return a + b; - }, 0); - } else { - checksum += product; - } - } else { - checksum += parseInt(str[i], 10); - } - - second = !second; - } - - return checksum % 10 === 0; -} -/* - * Reverse TIN multiplication and summation helper function - * Called with an array of single-digit integers and a base multiplier - * to calculate the sum of the digits multiplied in reverse. - * Normally used in variations of MOD 11 algorithmic checks. - */ - -function reverseMultiplyAndSum(digits, base) { - var total = 0; - - for (var i = 0; i < digits.length; i++) { - total += digits[i] * (base - i); - } - - return total; -} -/* - * Verhoeff validation helper function - * Called with a string of numbers - * to validate according to the Verhoeff algorithm. - */ - -function verhoeffCheck(str) { - var d_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]; - var p_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]]; // Copy (to prevent replacement) and reverse - - var str_copy = str.split('').reverse().join(''); - var checksum = 0; - - for (var i = 0; i < str_copy.length; i++) { - checksum = d_table[checksum][p_table[i % 8][parseInt(str_copy[i], 10)]]; - } - - return checksum === 0; -} - -/** - * TIN Validation - * Validates Tax Identification Numbers (TINs) from the US, EU member states and the United Kingdom. - * - * EU-UK: - * National TIN validity is calculated using public algorithms as made available by DG TAXUD. - * - * See `https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx` for more information. - * - * US: - * An Employer Identification Number (EIN), also known as a Federal Tax Identification Number, - * is used to identify a business entity. - * - * NOTES: - * - Prefix 47 is being reserved for future use - * - Prefixes 26, 27, 45, 46 and 47 were previously assigned by the Philadelphia campus. - * - * See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes` - * for more information. - */ -// Locale functions - -/* - * bg-BG validation function - * (Edinen graždanski nomer (EGN/ЕГН), persons only) - * Checks if birth date (first six digits) is valid and calculates check (last) digit - */ - -function bgBgCheck(tin) { - // Extract full year, normalize month and check birth date validity - var century_year = tin.slice(0, 2); - var month = parseInt(tin.slice(2, 4), 10); - - if (month > 40) { - month -= 40; - century_year = "20".concat(century_year); - } else if (month > 20) { - month -= 20; - century_year = "18".concat(century_year); - } else { - century_year = "19".concat(century_year); - } - - if (month < 10) { - month = "0".concat(month); - } - - var date = "".concat(century_year, "/").concat(month, "/").concat(tin.slice(4, 6)); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } // split digits into an array for further processing - - - var digits = tin.split('').map(function (a) { - return parseInt(a, 10); - }); // Calculate checksum by multiplying digits with fixed values - - var multip_lookup = [2, 4, 8, 5, 10, 9, 7, 3, 6]; - var checksum = 0; - - for (var i = 0; i < multip_lookup.length; i++) { - checksum += digits[i] * multip_lookup[i]; - } - - checksum = checksum % 11 === 10 ? 0 : checksum % 11; - return checksum === digits[9]; -} -/* - * cs-CZ validation function - * (Rodné číslo (RČ), persons only) - * Checks if birth date (first six digits) is valid and divisibility by 11 - * Material not in DG TAXUD document sourced from: - * -`https://lorenc.info/3MA381/overeni-spravnosti-rodneho-cisla.htm` - * -`https://www.mvcr.cz/clanek/rady-a-sluzby-dokumenty-rodne-cislo.aspx` - */ - - -function csCzCheck(tin) { - tin = tin.replace(/\W/, ''); // Extract full year from TIN length - - var full_year = parseInt(tin.slice(0, 2), 10); - - if (tin.length === 10) { - if (full_year < 54) { - full_year = "20".concat(full_year); - } else { - full_year = "19".concat(full_year); - } - } else { - if (tin.slice(6) === '000') { - return false; - } // Three-zero serial not assigned before 1954 - - - if (full_year < 54) { - full_year = "19".concat(full_year); - } else { - return false; // No 18XX years seen in any of the resources - } - } // Add missing zero if needed - - - if (full_year.length === 3) { - full_year = [full_year.slice(0, 2), '0', full_year.slice(2)].join(''); - } // Extract month from TIN and normalize - - - var month = parseInt(tin.slice(2, 4), 10); - - if (month > 50) { - month -= 50; - } - - if (month > 20) { - // Month-plus-twenty was only introduced in 2004 - if (parseInt(full_year, 10) < 2004) { - return false; - } - - month -= 20; - } - - if (month < 10) { - month = "0".concat(month); - } // Check date validity - - - var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6)); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } // Verify divisibility by 11 - - - if (tin.length === 10) { - if (parseInt(tin, 10) % 11 !== 0) { - // Some numbers up to and including 1985 are still valid if - // check (last) digit equals 0 and modulo of first 9 digits equals 10 - var checkdigit = parseInt(tin.slice(0, 9), 10) % 11; - - if (parseInt(full_year, 10) < 1986 && checkdigit === 10) { - if (parseInt(tin.slice(9), 10) !== 0) { - return false; - } - } else { - return false; - } - } - } - - return true; -} -/* - * de-AT validation function - * (Abgabenkontonummer, persons/entities) - * Verify TIN validity by calling luhnCheck() - */ - - -function deAtCheck(tin) { - return luhnCheck(tin); -} -/* - * de-DE validation function - * (Steueridentifikationsnummer (Steuer-IdNr.), persons only) - * Tests for single duplicate/triplicate value, then calculates ISO 7064 check (last) digit - * Partial implementation of spec (same result with both algorithms always) - */ - - -function deDeCheck(tin) { - // Split digits into an array for further processing - var digits = tin.split('').map(function (a) { - return parseInt(a, 10); - }); // Fill array with strings of number positions - - var occurences = []; - - for (var i = 0; i < digits.length - 1; i++) { - occurences.push(''); - - for (var j = 0; j < digits.length - 1; j++) { - if (digits[i] === digits[j]) { - occurences[i] += j; - } - } - } // Remove digits with one occurence and test for only one duplicate/triplicate - - - occurences = occurences.filter(function (a) { - return a.length > 1; - }); - - if (occurences.length !== 2 && occurences.length !== 3) { - return false; - } // In case of triplicate value only two digits are allowed next to each other - - - if (occurences[0].length === 3) { - var trip_locations = occurences[0].split('').map(function (a) { - return parseInt(a, 10); - }); - var recurrent = 0; // Amount of neighbour occurences - - for (var _i = 0; _i < trip_locations.length - 1; _i++) { - if (trip_locations[_i] + 1 === trip_locations[_i + 1]) { - recurrent += 1; - } - } - - if (recurrent === 2) { - return false; - } - } - - return iso7064Check(tin); -} -/* - * dk-DK validation function - * (CPR-nummer (personnummer), persons only) - * Checks if birth date (first six digits) is valid and assigned to century (seventh) digit, - * and calculates check (last) digit - */ - - -function dkDkCheck(tin) { - tin = tin.replace(/\W/, ''); // Extract year, check if valid for given century digit and add century - - var year = parseInt(tin.slice(4, 6), 10); - var century_digit = tin.slice(6, 7); - - switch (century_digit) { - case '0': - case '1': - case '2': - case '3': - year = "19".concat(year); - break; - - case '4': - case '9': - if (year < 37) { - year = "20".concat(year); - } else { - year = "19".concat(year); - } - - break; - - default: - if (year < 37) { - year = "20".concat(year); - } else if (year > 58) { - year = "18".concat(year); - } else { - return false; - } - - break; - } // Add missing zero if needed - - - if (year.length === 3) { - year = [year.slice(0, 2), '0', year.slice(2)].join(''); - } // Check date validity - - - var date = "".concat(year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2)); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } // Split digits into an array for further processing - - - var digits = tin.split('').map(function (a) { - return parseInt(a, 10); - }); - var checksum = 0; - var weight = 4; // Multiply by weight and add to checksum - - for (var i = 0; i < 9; i++) { - checksum += digits[i] * weight; - weight -= 1; - - if (weight === 1) { - weight = 7; - } - } - - checksum %= 11; - - if (checksum === 1) { - return false; - } - - return checksum === 0 ? digits[9] === 0 : digits[9] === 11 - checksum; -} -/* - * el-CY validation function - * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons only) - * Verify TIN validity by calculating ASCII value of check (last) character - */ - - -function elCyCheck(tin) { - // split digits into an array for further processing - var digits = tin.slice(0, 8).split('').map(function (a) { - return parseInt(a, 10); - }); - var checksum = 0; // add digits in even places - - for (var i = 1; i < digits.length; i += 2) { - checksum += digits[i]; - } // add digits in odd places - - - for (var _i2 = 0; _i2 < digits.length; _i2 += 2) { - if (digits[_i2] < 2) { - checksum += 1 - digits[_i2]; - } else { - checksum += 2 * (digits[_i2] - 2) + 5; - - if (digits[_i2] > 4) { - checksum += 2; - } - } - } - - return String.fromCharCode(checksum % 26 + 65) === tin.charAt(8); -} -/* - * el-GR validation function - * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons/entities) - * Verify TIN validity by calculating check (last) digit - * Algorithm not in DG TAXUD document- sourced from: - * - `http://epixeirisi.gr/%CE%9A%CE%A1%CE%99%CE%A3%CE%99%CE%9C%CE%91-%CE%98%CE%95%CE%9C%CE%91%CE%A4%CE%91-%CE%A6%CE%9F%CE%A1%CE%9F%CE%9B%CE%9F%CE%93%CE%99%CE%91%CE%A3-%CE%9A%CE%91%CE%99-%CE%9B%CE%9F%CE%93%CE%99%CE%A3%CE%A4%CE%99%CE%9A%CE%97%CE%A3/23791/%CE%91%CF%81%CE%B9%CE%B8%CE%BC%CF%8C%CF%82-%CE%A6%CE%BF%CF%81%CE%BF%CE%BB%CE%BF%CE%B3%CE%B9%CE%BA%CE%BF%CF%8D-%CE%9C%CE%B7%CF%84%CF%81%CF%8E%CE%BF%CF%85` - */ - - -function elGrCheck(tin) { - // split digits into an array for further processing - var digits = tin.split('').map(function (a) { - return parseInt(a, 10); - }); - var checksum = 0; - - for (var i = 0; i < 8; i++) { - checksum += digits[i] * Math.pow(2, 8 - i); - } - - return checksum % 11 === digits[8]; -} -/* - * en-GB validation function (should go here if needed) - * (National Insurance Number (NINO) or Unique Taxpayer Reference (UTR), - * persons/entities respectively) - */ - -/* - * en-IE validation function - * (Personal Public Service Number (PPS No), persons only) - * Verify TIN validity by calculating check (second to last) character - */ - - -function enIeCheck(tin) { - var checksum = reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) { - return parseInt(a, 10); - }), 8); - - if (tin.length === 9 && tin[8] !== 'W') { - checksum += (tin[8].charCodeAt(0) - 64) * 9; - } - - checksum %= 23; - - if (checksum === 0) { - return tin[7].toUpperCase() === 'W'; - } - - return tin[7].toUpperCase() === String.fromCharCode(64 + checksum); -} // Valid US IRS campus prefixes - - -var enUsCampusPrefix = { - andover: ['10', '12'], - atlanta: ['60', '67'], - austin: ['50', '53'], - brookhaven: ['01', '02', '03', '04', '05', '06', '11', '13', '14', '16', '21', '22', '23', '25', '34', '51', '52', '54', '55', '56', '57', '58', '59', '65'], - cincinnati: ['30', '32', '35', '36', '37', '38', '61'], - fresno: ['15', '24'], - internet: ['20', '26', '27', '45', '46', '47'], - kansas: ['40', '44'], - memphis: ['94', '95'], - ogden: ['80', '90'], - philadelphia: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'], - sba: ['31'] -}; // Return an array of all US IRS campus prefixes - -function enUsGetPrefixes() { - var prefixes = []; - - for (var location in enUsCampusPrefix) { - // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes - // istanbul ignore else - if (enUsCampusPrefix.hasOwnProperty(location)) { - prefixes.push.apply(prefixes, _toConsumableArray(enUsCampusPrefix[location])); - } - } - - return prefixes; -} -/* - * en-US validation function - * Verify that the TIN starts with a valid IRS campus prefix - */ - - -function enUsCheck(tin) { - return enUsGetPrefixes().indexOf(tin.substr(0, 2)) !== -1; -} -/* - * es-ES validation function - * (Documento Nacional de Identidad (DNI) - * or Número de Identificación de Extranjero (NIE), persons only) - * Verify TIN validity by calculating check (last) character - */ - - -function esEsCheck(tin) { - // Split characters into an array for further processing - var chars = tin.toUpperCase().split(''); // Replace initial letter if needed - - if (isNaN(parseInt(chars[0], 10)) && chars.length > 1) { - var lead_replace = 0; - - switch (chars[0]) { - case 'Y': - lead_replace = 1; - break; - - case 'Z': - lead_replace = 2; - break; - - default: - } - - chars.splice(0, 1, lead_replace); // Fill with zeros if smaller than proper - } else { - while (chars.length < 9) { - chars.unshift(0); - } - } // Calculate checksum and check according to lookup - - - var lookup = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E']; - chars = chars.join(''); - var checksum = parseInt(chars.slice(0, 8), 10) % 23; - return chars[8] === lookup[checksum]; -} -/* - * et-EE validation function - * (Isikukood (IK), persons only) - * Checks if birth date (century digit and six following) is valid and calculates check (last) digit - * Material not in DG TAXUD document sourced from: - * - `https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Estonia-TIN.pdf` - */ - - -function etEeCheck(tin) { - // Extract year and add century - var full_year = tin.slice(1, 3); - var century_digit = tin.slice(0, 1); - - switch (century_digit) { - case '1': - case '2': - full_year = "18".concat(full_year); - break; - - case '3': - case '4': - full_year = "19".concat(full_year); - break; - - default: - full_year = "20".concat(full_year); - break; - } // Check date validity - - - var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7)); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } // Split digits into an array for further processing - - - var digits = tin.split('').map(function (a) { - return parseInt(a, 10); - }); - var checksum = 0; - var weight = 1; // Multiply by weight and add to checksum - - for (var i = 0; i < 10; i++) { - checksum += digits[i] * weight; - weight += 1; - - if (weight === 10) { - weight = 1; - } - } // Do again if modulo 11 of checksum is 10 - - - if (checksum % 11 === 10) { - checksum = 0; - weight = 3; - - for (var _i3 = 0; _i3 < 10; _i3++) { - checksum += digits[_i3] * weight; - weight += 1; - - if (weight === 10) { - weight = 1; - } - } - - if (checksum % 11 === 10) { - return digits[10] === 0; - } - } - - return checksum % 11 === digits[10]; -} -/* - * fi-FI validation function - * (Henkilötunnus (HETU), persons only) - * Checks if birth date (first six digits plus century symbol) is valid - * and calculates check (last) digit - */ - - -function fiFiCheck(tin) { - // Extract year and add century - var full_year = tin.slice(4, 6); - var century_symbol = tin.slice(6, 7); - - switch (century_symbol) { - case '+': - full_year = "18".concat(full_year); - break; - - case '-': - full_year = "19".concat(full_year); - break; - - default: - full_year = "20".concat(full_year); - break; - } // Check date validity - - - var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2)); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } // Calculate check character - - - var checksum = parseInt(tin.slice(0, 6) + tin.slice(7, 10), 10) % 31; - - if (checksum < 10) { - return checksum === parseInt(tin.slice(10), 10); - } - - checksum -= 10; - var letters_lookup = ['A', 'B', 'C', 'D', 'E', 'F', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y']; - return letters_lookup[checksum] === tin.slice(10); -} -/* - * fr/nl-BE validation function - * (Numéro national (N.N.), persons only) - * Checks if birth date (first six digits) is valid and calculates check (last two) digits - */ - - -function frBeCheck(tin) { - // Zero month/day value is acceptable - if (tin.slice(2, 4) !== '00' || tin.slice(4, 6) !== '00') { - // Extract date from first six digits of TIN - var date = "".concat(tin.slice(0, 2), "/").concat(tin.slice(2, 4), "/").concat(tin.slice(4, 6)); - - if (!isDate(date, 'YY/MM/DD')) { - return false; - } - } - - var checksum = 97 - parseInt(tin.slice(0, 9), 10) % 97; - var checkdigits = parseInt(tin.slice(9, 11), 10); - - if (checksum !== checkdigits) { - checksum = 97 - parseInt("2".concat(tin.slice(0, 9)), 10) % 97; - - if (checksum !== checkdigits) { - return false; - } - } - - return true; -} -/* - * fr-FR validation function - * (Numéro fiscal de référence (numéro SPI), persons only) - * Verify TIN validity by calculating check (last three) digits - */ - - -function frFrCheck(tin) { - tin = tin.replace(/\s/g, ''); - var checksum = parseInt(tin.slice(0, 10), 10) % 511; - var checkdigits = parseInt(tin.slice(10, 13), 10); - return checksum === checkdigits; -} -/* - * fr/lb-LU validation function - * (numéro d’identification personnelle, persons only) - * Verify birth date validity and run Luhn and Verhoeff checks - */ - - -function frLuCheck(tin) { - // Extract date and check validity - var date = "".concat(tin.slice(0, 4), "/").concat(tin.slice(4, 6), "/").concat(tin.slice(6, 8)); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } // Run Luhn check - - - if (!luhnCheck(tin.slice(0, 12))) { - return false; - } // Remove Luhn check digit and run Verhoeff check - - - return verhoeffCheck("".concat(tin.slice(0, 11)).concat(tin[12])); -} -/* - * hr-HR validation function - * (Osobni identifikacijski broj (OIB), persons/entities) - * Verify TIN validity by calling iso7064Check(digits) - */ - - -function hrHrCheck(tin) { - return iso7064Check(tin); -} -/* - * hu-HU validation function - * (Adóazonosító jel, persons only) - * Verify TIN validity by calculating check (last) digit - */ - - -function huHuCheck(tin) { - // split digits into an array for further processing - var digits = tin.split('').map(function (a) { - return parseInt(a, 10); - }); - var checksum = 8; - - for (var i = 1; i < 9; i++) { - checksum += digits[i] * (i + 1); - } - - return checksum % 11 === digits[9]; -} -/* - * lt-LT validation function (should go here if needed) - * (Asmens kodas, persons/entities respectively) - * Current validation check is alias of etEeCheck- same format applies - */ - -/* - * it-IT first/last name validity check - * Accepts it-IT TIN-encoded names as a three-element character array and checks their validity - * Due to lack of clarity between resources ("Are only Italian consonants used? - * What happens if a person has X in their name?" etc.) only two test conditions - * have been implemented: - * Vowels may only be followed by other vowels or an X character - * and X characters after vowels may only be followed by other X characters. - */ - - -function itItNameCheck(name) { - // true at the first occurence of a vowel - var vowelflag = false; // true at the first occurence of an X AFTER vowel - // (to properly handle last names with X as consonant) - - var xflag = false; - - for (var i = 0; i < 3; i++) { - if (!vowelflag && /[AEIOU]/.test(name[i])) { - vowelflag = true; - } else if (!xflag && vowelflag && name[i] === 'X') { - xflag = true; - } else if (i > 0) { - if (vowelflag && !xflag) { - if (!/[AEIOU]/.test(name[i])) { - return false; - } - } - - if (xflag) { - if (!/X/.test(name[i])) { - return false; - } - } - } - } - - return true; -} -/* - * it-IT validation function - * (Codice fiscale (TIN-IT), persons only) - * Verify name, birth date and codice catastale validity - * and calculate check character. - * Material not in DG-TAXUD document sourced from: - * `https://en.wikipedia.org/wiki/Italian_fiscal_code` - */ - - -function itItCheck(tin) { - // Capitalize and split characters into an array for further processing - var chars = tin.toUpperCase().split(''); // Check first and last name validity calling itItNameCheck() - - if (!itItNameCheck(chars.slice(0, 3))) { - return false; - } - - if (!itItNameCheck(chars.slice(3, 6))) { - return false; - } // Convert letters in number spaces back to numbers if any - - - var number_locations = [6, 7, 9, 10, 12, 13, 14]; - var number_replace = { - L: '0', - M: '1', - N: '2', - P: '3', - Q: '4', - R: '5', - S: '6', - T: '7', - U: '8', - V: '9' - }; - - for (var _i4 = 0, _number_locations = number_locations; _i4 < _number_locations.length; _i4++) { - var i = _number_locations[_i4]; - - if (chars[i] in number_replace) { - chars.splice(i, 1, number_replace[chars[i]]); - } - } // Extract month and day, and check date validity - - - var month_replace = { - A: '01', - B: '02', - C: '03', - D: '04', - E: '05', - H: '06', - L: '07', - M: '08', - P: '09', - R: '10', - S: '11', - T: '12' - }; - var month = month_replace[chars[8]]; - var day = parseInt(chars[9] + chars[10], 10); - - if (day > 40) { - day -= 40; - } - - if (day < 10) { - day = "0".concat(day); - } - - var date = "".concat(chars[6]).concat(chars[7], "/").concat(month, "/").concat(day); - - if (!isDate(date, 'YY/MM/DD')) { - return false; - } // Calculate check character by adding up even and odd characters as numbers - - - var checksum = 0; - - for (var _i5 = 1; _i5 < chars.length - 1; _i5 += 2) { - var char_to_int = parseInt(chars[_i5], 10); - - if (isNaN(char_to_int)) { - char_to_int = chars[_i5].charCodeAt(0) - 65; - } - - checksum += char_to_int; - } - - var odd_convert = { - // Maps of characters at odd places - A: 1, - B: 0, - C: 5, - D: 7, - E: 9, - F: 13, - G: 15, - H: 17, - I: 19, - J: 21, - K: 2, - L: 4, - M: 18, - N: 20, - O: 11, - P: 3, - Q: 6, - R: 8, - S: 12, - T: 14, - U: 16, - V: 10, - W: 22, - X: 25, - Y: 24, - Z: 23, - 0: 1, - 1: 0 - }; - - for (var _i6 = 0; _i6 < chars.length - 1; _i6 += 2) { - var _char_to_int = 0; - - if (chars[_i6] in odd_convert) { - _char_to_int = odd_convert[chars[_i6]]; - } else { - var multiplier = parseInt(chars[_i6], 10); - _char_to_int = 2 * multiplier + 1; - - if (multiplier > 4) { - _char_to_int += 2; - } - } - - checksum += _char_to_int; - } - - if (String.fromCharCode(65 + checksum % 26) !== chars[15]) { - return false; - } - - return true; -} -/* - * lv-LV validation function - * (Personas kods (PK), persons only) - * Check validity of birth date and calculate check (last) digit - * Support only for old format numbers (not starting with '32', issued before 2017/07/01) - * Material not in DG TAXUD document sourced from: - * `https://boot.ritakafija.lv/forums/index.php?/topic/88314-personas-koda-algoritms-%C4%8Deksumma/` - */ - - -function lvLvCheck(tin) { - tin = tin.replace(/\W/, ''); // Extract date from TIN - - var day = tin.slice(0, 2); - - if (day !== '32') { - // No date/checksum check if new format - var month = tin.slice(2, 4); - - if (month !== '00') { - // No date check if unknown month - var full_year = tin.slice(4, 6); - - switch (tin[6]) { - case '0': - full_year = "18".concat(full_year); - break; - - case '1': - full_year = "19".concat(full_year); - break; - - default: - full_year = "20".concat(full_year); - break; - } // Check date validity - - - var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(day); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } - } // Calculate check digit - - - var checksum = 1101; - var multip_lookup = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; - - for (var i = 0; i < tin.length - 1; i++) { - checksum -= parseInt(tin[i], 10) * multip_lookup[i]; - } - - return parseInt(tin[10], 10) === checksum % 11; - } - - return true; -} -/* - * mt-MT validation function - * (Identity Card Number or Unique Taxpayer Reference, persons/entities) - * Verify Identity Card Number structure (no other tests found) - */ - - -function mtMtCheck(tin) { - if (tin.length !== 9) { - // No tests for UTR - var chars = tin.toUpperCase().split(''); // Fill with zeros if smaller than proper - - while (chars.length < 8) { - chars.unshift(0); - } // Validate format according to last character - - - switch (tin[7]) { - case 'A': - case 'P': - if (parseInt(chars[6], 10) === 0) { - return false; - } - - break; - - default: - { - var first_part = parseInt(chars.join('').slice(0, 5), 10); - - if (first_part > 32000) { - return false; - } - - var second_part = parseInt(chars.join('').slice(5, 7), 10); - - if (first_part === second_part) { - return false; - } - } - } - } - - return true; -} -/* - * nl-NL validation function - * (Burgerservicenummer (BSN) or Rechtspersonen Samenwerkingsverbanden Informatie Nummer (RSIN), - * persons/entities respectively) - * Verify TIN validity by calculating check (last) digit (variant of MOD 11) - */ - - -function nlNlCheck(tin) { - return reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) { - return parseInt(a, 10); - }), 9) % 11 === parseInt(tin[8], 10); -} -/* - * pl-PL validation function - * (Powszechny Elektroniczny System Ewidencji Ludności (PESEL) - * or Numer identyfikacji podatkowej (NIP), persons/entities) - * Verify TIN validity by validating birth date (PESEL) and calculating check (last) digit - */ - - -function plPlCheck(tin) { - // NIP - if (tin.length === 10) { - // Calculate last digit by multiplying with lookup - var lookup = [6, 5, 7, 2, 3, 4, 5, 6, 7]; - var _checksum = 0; - - for (var i = 0; i < lookup.length; i++) { - _checksum += parseInt(tin[i], 10) * lookup[i]; - } - - _checksum %= 11; - - if (_checksum === 10) { - return false; - } - - return _checksum === parseInt(tin[9], 10); - } // PESEL - // Extract full year using month - - - var full_year = tin.slice(0, 2); - var month = parseInt(tin.slice(2, 4), 10); - - if (month > 80) { - full_year = "18".concat(full_year); - month -= 80; - } else if (month > 60) { - full_year = "22".concat(full_year); - month -= 60; - } else if (month > 40) { - full_year = "21".concat(full_year); - month -= 40; - } else if (month > 20) { - full_year = "20".concat(full_year); - month -= 20; - } else { - full_year = "19".concat(full_year); - } // Add leading zero to month if needed - - - if (month < 10) { - month = "0".concat(month); - } // Check date validity - - - var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6)); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } // Calculate last digit by mulitplying with odd one-digit numbers except 5 - - - var checksum = 0; - var multiplier = 1; - - for (var _i7 = 0; _i7 < tin.length - 1; _i7++) { - checksum += parseInt(tin[_i7], 10) * multiplier % 10; - multiplier += 2; - - if (multiplier > 10) { - multiplier = 1; - } else if (multiplier === 5) { - multiplier += 2; - } - } - - checksum = 10 - checksum % 10; - return checksum === parseInt(tin[10], 10); -} -/* - * pt-PT validation function - * (Número de identificação fiscal (NIF), persons/entities) - * Verify TIN validity by calculating check (last) digit (variant of MOD 11) - */ - - -function ptPtCheck(tin) { - var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) { - return parseInt(a, 10); - }), 9) % 11; - - if (checksum > 9) { - return parseInt(tin[8], 10) === 0; - } - - return checksum === parseInt(tin[8], 10); -} -/* - * ro-RO validation function - * (Cod Numeric Personal (CNP) or Cod de înregistrare fiscală (CIF), - * persons only) - * Verify CNP validity by calculating check (last) digit (test not found for CIF) - * Material not in DG TAXUD document sourced from: - * `https://en.wikipedia.org/wiki/National_identification_number#Romania` - */ - - -function roRoCheck(tin) { - if (tin.slice(0, 4) !== '9000') { - // No test found for this format - // Extract full year using century digit if possible - var full_year = tin.slice(1, 3); - - switch (tin[0]) { - case '1': - case '2': - full_year = "19".concat(full_year); - break; - - case '3': - case '4': - full_year = "18".concat(full_year); - break; - - case '5': - case '6': - full_year = "20".concat(full_year); - break; - - default: - } // Check date validity - - - var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7)); - - if (date.length === 8) { - if (!isDate(date, 'YY/MM/DD')) { - return false; - } - } else if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } // Calculate check digit - - - var digits = tin.split('').map(function (a) { - return parseInt(a, 10); - }); - var multipliers = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9]; - var checksum = 0; - - for (var i = 0; i < multipliers.length; i++) { - checksum += digits[i] * multipliers[i]; - } - - if (checksum % 11 === 10) { - return digits[12] === 1; - } - - return digits[12] === checksum % 11; - } - - return true; -} -/* - * sk-SK validation function - * (Rodné číslo (RČ) or bezvýznamové identifikačné číslo (BIČ), persons only) - * Checks validity of pre-1954 birth numbers (rodné číslo) only - * Due to the introduction of the pseudo-random BIČ it is not possible to test - * post-1954 birth numbers without knowing whether they are BIČ or RČ beforehand - */ - - -function skSkCheck(tin) { - if (tin.length === 9) { - tin = tin.replace(/\W/, ''); - - if (tin.slice(6) === '000') { - return false; - } // Three-zero serial not assigned before 1954 - // Extract full year from TIN length - - - var full_year = parseInt(tin.slice(0, 2), 10); - - if (full_year > 53) { - return false; - } - - if (full_year < 10) { - full_year = "190".concat(full_year); - } else { - full_year = "19".concat(full_year); - } // Extract month from TIN and normalize - - - var month = parseInt(tin.slice(2, 4), 10); - - if (month > 50) { - month -= 50; - } - - if (month < 10) { - month = "0".concat(month); - } // Check date validity - - - var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6)); - - if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } - } - - return true; -} -/* - * sl-SI validation function - * (Davčna številka, persons/entities) - * Verify TIN validity by calculating check (last) digit (variant of MOD 11) - */ - - -function slSiCheck(tin) { - var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) { - return parseInt(a, 10); - }), 8) % 11; - - if (checksum === 10) { - return parseInt(tin[7], 10) === 0; - } - - return checksum === parseInt(tin[7], 10); -} -/* - * sv-SE validation function - * (Personnummer or samordningsnummer, persons only) - * Checks validity of birth date and calls luhnCheck() to validate check (last) digit - */ - - -function svSeCheck(tin) { - // Make copy of TIN and normalize to two-digit year form - var tin_copy = tin.slice(0); - - if (tin.length > 11) { - tin_copy = tin_copy.slice(2); - } // Extract date of birth - - - var full_year = ''; - var month = tin_copy.slice(2, 4); - var day = parseInt(tin_copy.slice(4, 6), 10); - - if (tin.length > 11) { - full_year = tin.slice(0, 4); - } else { - full_year = tin.slice(0, 2); - - if (tin.length === 11 && day < 60) { - // Extract full year from centenarian symbol - // Should work just fine until year 10000 or so - var current_year = new Date().getFullYear().toString(); - var current_century = parseInt(current_year.slice(0, 2), 10); - current_year = parseInt(current_year, 10); - - if (tin[6] === '-') { - if (parseInt("".concat(current_century).concat(full_year), 10) > current_year) { - full_year = "".concat(current_century - 1).concat(full_year); - } else { - full_year = "".concat(current_century).concat(full_year); - } - } else { - full_year = "".concat(current_century - 1).concat(full_year); - - if (current_year - parseInt(full_year, 10) < 100) { - return false; - } - } - } - } // Normalize day and check date validity - - - if (day > 60) { - day -= 60; - } - - if (day < 10) { - day = "0".concat(day); - } - - var date = "".concat(full_year, "/").concat(month, "/").concat(day); - - if (date.length === 8) { - if (!isDate(date, 'YY/MM/DD')) { - return false; - } - } else if (!isDate(date, 'YYYY/MM/DD')) { - return false; - } - - return luhnCheck(tin.replace(/\W/, '')); -} // Locale lookup objects - -/* - * Tax id regex formats for various locales - * - * Where not explicitly specified in DG-TAXUD document both - * uppercase and lowercase letters are acceptable. - */ - - -var taxIdFormat = { - 'bg-BG': /^\d{10}$/, - 'cs-CZ': /^\d{6}\/{0,1}\d{3,4}$/, - 'de-AT': /^\d{9}$/, - 'de-DE': /^[1-9]\d{10}$/, - 'dk-DK': /^\d{6}-{0,1}\d{4}$/, - 'el-CY': /^[09]\d{7}[A-Z]$/, - 'el-GR': /^([0-4]|[7-9])\d{8}$/, - 'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i, - 'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i, - 'en-US': /^\d{2}[- ]{0,1}\d{7}$/, - 'es-ES': /^(\d{0,8}|[XYZKLM]\d{7})[A-HJ-NP-TV-Z]$/i, - 'et-EE': /^[1-6]\d{6}(00[1-9]|0[1-9][0-9]|[1-6][0-9]{2}|70[0-9]|710)\d$/, - 'fi-FI': /^\d{6}[-+A]\d{3}[0-9A-FHJ-NPR-Y]$/i, - 'fr-BE': /^\d{11}$/, - 'fr-FR': /^[0-3]\d{12}$|^[0-3]\d\s\d{2}(\s\d{3}){3}$/, - // Conforms both to official spec and provided example - 'fr-LU': /^\d{13}$/, - 'hr-HR': /^\d{11}$/, - 'hu-HU': /^8\d{9}$/, - 'it-IT': /^[A-Z]{6}[L-NP-V0-9]{2}[A-EHLMPRST][L-NP-V0-9]{2}[A-ILMZ][L-NP-V0-9]{3}[A-Z]$/i, - 'lv-LV': /^\d{6}-{0,1}\d{5}$/, - // Conforms both to DG TAXUD spec and original research - 'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i, - 'nl-NL': /^\d{9}$/, - 'pl-PL': /^\d{10,11}$/, - 'pt-PT': /^\d{9}$/, - 'ro-RO': /^\d{13}$/, - 'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/, - 'sl-SI': /^[1-9]\d{7}$/, - 'sv-SE': /^(\d{6}[-+]{0,1}\d{4}|(18|19|20)\d{6}[-+]{0,1}\d{4})$/ -}; // taxIdFormat locale aliases - -taxIdFormat['lb-LU'] = taxIdFormat['fr-LU']; -taxIdFormat['lt-LT'] = taxIdFormat['et-EE']; -taxIdFormat['nl-BE'] = taxIdFormat['fr-BE']; // Algorithmic tax id check functions for various locales - -var taxIdCheck = { - 'bg-BG': bgBgCheck, - 'cs-CZ': csCzCheck, - 'de-AT': deAtCheck, - 'de-DE': deDeCheck, - 'dk-DK': dkDkCheck, - 'el-CY': elCyCheck, - 'el-GR': elGrCheck, - 'en-IE': enIeCheck, - 'en-US': enUsCheck, - 'es-ES': esEsCheck, - 'et-EE': etEeCheck, - 'fi-FI': fiFiCheck, - 'fr-BE': frBeCheck, - 'fr-FR': frFrCheck, - 'fr-LU': frLuCheck, - 'hr-HR': hrHrCheck, - 'hu-HU': huHuCheck, - 'it-IT': itItCheck, - 'lv-LV': lvLvCheck, - 'mt-MT': mtMtCheck, - 'nl-NL': nlNlCheck, - 'pl-PL': plPlCheck, - 'pt-PT': ptPtCheck, - 'ro-RO': roRoCheck, - 'sk-SK': skSkCheck, - 'sl-SI': slSiCheck, - 'sv-SE': svSeCheck -}; // taxIdCheck locale aliases - -taxIdCheck['lb-LU'] = taxIdCheck['fr-LU']; -taxIdCheck['lt-LT'] = taxIdCheck['et-EE']; -taxIdCheck['nl-BE'] = taxIdCheck['fr-BE']; // Regexes for locales where characters should be omitted before checking format - -var allsymbols = /[-\\\/!@#$%\^&\*\(\)\+\=\[\]]+/g; -var sanitizeRegexes = { - 'de-AT': allsymbols, - 'de-DE': /[\/\\]/g, - 'fr-BE': allsymbols -}; // sanitizeRegexes locale aliases - -sanitizeRegexes['nl-BE'] = sanitizeRegexes['fr-BE']; -/* - * Validator function - * Return true if the passed string is a valid tax identification number - * for the specified locale. - * Throw an error exception if the locale is not supported. - */ - -function isTaxID(str) { - var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US'; - assertString(str); // Copy TIN to avoid replacement if sanitized - - var strcopy = str.slice(0); - - if (locale in taxIdFormat) { - if (locale in sanitizeRegexes) { - strcopy = strcopy.replace(sanitizeRegexes[locale], ''); - } - - if (!taxIdFormat[locale].test(strcopy)) { - return false; - } - - if (locale in taxIdCheck) { - return taxIdCheck[locale](strcopy); - } // Fallthrough; not all locales have algorithmic checks - - - return true; - } - - throw new Error("Invalid locale '".concat(locale, "'")); -} - -/* eslint-disable max-len */ - -var phones = { - 'am-AM': /^(\+?374|0)((10|[9|7][0-9])\d{6}$|[2-4]\d{7}$)/, - 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/, - 'ar-BH': /^(\+?973)?(3|6)\d{7}$/, - 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/, - 'ar-LB': /^(\+?961)?((3|81)\d{6}|7\d{7})$/, - '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-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/, - 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/, - 'ar-OM': /^((\+|00)968)?(9[1-9])\d{6}$/, - 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/, - 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, - 'ar-TN': /^(\+?216)?[2459]\d{7}$/, - 'az-AZ': /^(\+994|0)(5[015]|7[07]|99)\d{7}$/, - 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/, - 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/, - 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/, - 'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/, - 'ca-AD': /^(\+376)?[346]\d{5}$/, - '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|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/, - 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/, - 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/, - 'de-LU': /^(\+352)?((6\d1)\d{6})$/, - 'el-GR': /^(\+?30|0)?(69\d{8})$/, - 'en-AU': /^(\+?61|0)4\d{8}$/, - 'en-GB': /^(\+?44|0)7\d{9}$/, - 'en-GG': /^(\+?44|0)1481\d{6}$/, - 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/, - 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/, - 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/, - 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, - 'en-IN': /^(\+?91|0)?[6789]\d{9}$/, - 'en-KE': /^(\+?254|0)(7|1)\d{8}$/, - 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/, - '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-PH': /^(09|\+639)\d{9}$/, - 'en-RW': /^(\+?250|0)?[7]\d{8}$/, - 'en-SG': /^(\+65)?[689]\d{7}$/, - 'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/, - '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}$/, - 'en-ZW': /^(\+263)[0-9]{9}$/, - 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/, - 'es-BO': /^(\+?591)?(6|7)\d{7}$/, - 'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[0-9]{1}\d{6}$/, - 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/, - 'es-CR': /^(\+506)?[2-8]\d{7}$/, - 'es-DO': /^(\+?1)?8[024]9\d{7}$/, - 'es-HN': /^(\+?504)?[9|8]\d{7}$/, - 'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/, - 'es-ES': /^(\+?34)?[6|7]\d{8}$/, - 'es-PE': /^(\+?51)?9\d{8}$/, - 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/, - 'es-PA': /^(\+?507)\d{7,8}$/, - '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$/, - 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/, - 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, - 'fr-FR': /^(\+?33|0)[67]\d{8}$/, - 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, - 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, - 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/, - 'fr-RE': /^(\+?262|0|00262)[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}$/, - 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/, - 'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/, - 'ka-GE': /^(\+?995)?(5|79)\d{7}$/, - '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}$/, - 'ne-NP': /^(\+?977)?9[78]\d{8}$/, - 'nl-BE': /^(\+?32|0)4?\d{8}$/, - 'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/, - 'nn-NO': /^(\+?47)?[49]\d{7}$/, - 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/, - 'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[2-9]{1}\d{3}\-?\d{4}))$/, - 'pt-PT': /^(\+?351)?9[1236]\d{7}$/, - 'pt-AO': /^(\+244)\d{9}$/, - '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}$/, - 'sq-AL': /^(\+355|0)6[789]\d{6}$/, - '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}$/, - 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, - 'vi-VN': /^(\+?84|0)((3([2-9]))|(5([2689]))|(7([0|6-9]))|(8([1-6|89]))|(9([0-9])))([0-9]{7})$/, - 'zh-CN': /^((\+|00)86)?1([3568][0-9]|4[579]|6[67]|7[01235678]|9[012356789])[0-9]{8}$/, - 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/ -}; -/* eslint-enable max-len */ -// aliases - -phones['en-CA'] = phones['en-US']; -phones['fr-CA'] = phones['en-CA']; -phones['fr-BE'] = phones['nl-BE']; -phones['zh-HK'] = phones['en-HK']; -phones['zh-MO'] = phones['en-MO']; -phones['ga-IE'] = phones['en-IE']; -phones['fr-CH'] = phones['de-CH']; -phones['it-CH'] = phones['fr-CH']; -function isMobilePhone(str, locale, options) { - assertString(str); - - if (options && options.strictMode && !str.startsWith('+')) { - return false; - } - - if (Array.isArray(locale)) { - return locale.some(function (key) { - // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes - // istanbul ignore else - if (phones.hasOwnProperty(key)) { - var phone = phones[key]; - - if (phone.test(str)) { - return true; - } - } - - return false; - }); - } else if (locale in phones) { - return phones[locale].test(str); // alias falsey locale as 'any' - } else if (!locale || locale === 'any') { - for (var key in phones) { - // istanbul ignore else - if (phones.hasOwnProperty(key)) { - var phone = phones[key]; - - if (phone.test(str)) { - return true; - } - } - } - - return false; - } - - throw new Error("Invalid locale '".concat(locale, "'")); -} -var locales$3 = Object.keys(phones); - -var eth = /^(0x)[0-9a-f]{40}$/i; -function isEthereumAddress(str) { - assertString(str); - return eth.test(str); -} - -function currencyRegex(options) { - var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}"); - options.digits_after_decimal.forEach(function (digit, index) { - if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}"); - }); - var symbol = "(".concat(options.symbol.replace(/\W/, function (m) { - return "\\".concat(m); - }), ")").concat(options.require_symbol ? '' : '?'), - negative = '-?', - whole_dollar_amount_without_sep = '[1-9]\\d*', - whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"), - valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep], - whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"), - decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?'); - var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : ''); // default is negative sign before symbol, but there are two other options (besides parens) - - if (options.allow_negatives && !options.parens_for_negatives) { - if (options.negative_sign_after_digits) { - pattern += negative; - } else if (options.negative_sign_before_digits) { - pattern = negative + pattern; - } - } // South African Rand, for example, uses R 123 (space) and R-123 (no space) - - - if (options.allow_negative_sign_placeholder) { - pattern = "( (?!\\-))?".concat(pattern); - } else if (options.allow_space_after_symbol) { - pattern = " ?".concat(pattern); - } else if (options.allow_space_after_digits) { - pattern += '( (?!$))?'; - } - - if (options.symbol_after_digits) { - pattern += symbol; - } else { - pattern = symbol + pattern; - } - - if (options.allow_negatives) { - if (options.parens_for_negatives) { - pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")"); - } else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) { - pattern = negative + pattern; - } - } // ensure there's a dollar and/or decimal amount, and that - // it doesn't start with a space or a negative sign followed by a space - - - return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$")); -} - -var default_currency_options = { - 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 -}; -function isCurrency(str, options) { - assertString(str); - options = merge(options, default_currency_options); - return currencyRegex(options).test(str); -} - -var bech32 = /^(bc1)[a-z0-9]{25,39}$/; -var base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/; -function isBtcAddress(str) { - assertString(str); // check for bech32 - - if (str.startsWith('bc1')) { - return bech32.test(str); - } - - return base58.test(str); -} - -/* eslint-disable max-len */ -// from http://goo.gl/0ejHHW - -var iso8601 = /^([\+-]?\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)?)?)?)?$/; // same as above, except with a strict 'T' separator between date and time - -var iso8601StrictSeparator = /^([\+-]?\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]((([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)?)?)?)?$/; -/* eslint-enable max-len */ - -var isValidDate = function isValidDate(str) { - // str must have passed the ISO8601 check - // this check is meant to catch invalid dates - // like 2009-02-31 - // first check for ordinal dates - var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/); - - if (ordinalMatch) { - var oYear = Number(ordinalMatch[1]); - var oDay = Number(ordinalMatch[2]); // if is leap year - - if (oYear % 4 === 0 && oYear % 100 !== 0 || oYear % 400 === 0) return oDay <= 366; - return oDay <= 365; - } - - var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number); - var year = match[1]; - var month = match[2]; - var day = match[3]; - var monthString = month ? "0".concat(month).slice(-2) : month; - var dayString = day ? "0".concat(day).slice(-2) : day; // create a date object and compare - - var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01')); - - if (month && day) { - return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day; - } - - return true; -}; - -function isISO8601(str) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - assertString(str); - var check = options.strictSeparator ? iso8601StrictSeparator.test(str) : iso8601.test(str); - if (check && options.strict) return isValidDate(str); - return check; -} - -/* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */ - -var dateFullYear = /[0-9]{4}/; -var dateMonth = /(0[1-9]|1[0-2])/; -var dateMDay = /([12]\d|0[1-9]|3[01])/; -var timeHour = /([01][0-9]|2[0-3])/; -var timeMinute = /[0-5][0-9]/; -var timeSecond = /([0-5][0-9]|60)/; -var timeSecFrac = /(\.[0-9]+)?/; -var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source)); -var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")")); -var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source)); -var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source)); -var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source)); -var rfc3339 = new RegExp("".concat(fullDate.source, "[ tT]").concat(fullTime.source)); -function isRFC3339(str) { - assertString(str); - return rfc3339.test(str); -} - -var validISO31661Alpha2CountriesCodes = ['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']; -function isISO31661Alpha2(str) { - assertString(str); - return includes(validISO31661Alpha2CountriesCodes, str.toUpperCase()); -} - -var validISO31661Alpha3CountriesCodes = ['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']; -function isISO31661Alpha3(str) { - assertString(str); - return includes(validISO31661Alpha3CountriesCodes, str.toUpperCase()); -} - -var base32 = /^[A-Z2-7]+=*$/; -function isBase32(str) { - assertString(str); - var len = str.length; - - if (len % 8 === 0 && base32.test(str)) { - return true; - } - - return false; -} - -var base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/; -function isBase58(str) { - assertString(str); - - if (base58Reg.test(str)) { - return true; - } - - return false; -} - -var validMediaType = /^[a-z]+\/[a-z0-9\-\+]+$/i; -var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i; -var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i; -function isDataURI(str) { - assertString(str); - var data = str.split(','); - - if (data.length < 2) { - return false; - } - - var attributes = data.shift().trim().split(';'); - var schemeAndMediaType = attributes.shift(); - - if (schemeAndMediaType.substr(0, 5) !== 'data:') { - return false; - } - - var mediaType = schemeAndMediaType.substr(5); - - if (mediaType !== '' && !validMediaType.test(mediaType)) { - return false; - } - - for (var i = 0; i < attributes.length; i++) { - if (i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') {// ok - } else if (!validAttribute.test(attributes[i])) { - return false; - } - } - - for (var _i = 0; _i < data.length; _i++) { - if (!validData.test(data[_i])) { - return false; - } - } - - return true; -} - -var magnetURI = /^magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32,40}&dn=.+&tr=.+$/i; -function isMagnetURI(url) { - assertString(url); - return magnetURI.test(url.trim()); -} - -/* - Checks if the provided string matches to a correct Media type format (MIME type) - - This function only checks is the string format follows the - etablished rules by the according RFC specifications. - This function supports 'charset' in textual media types - (https://tools.ietf.org/html/rfc6657). - - This function does not check against all the media types listed - by the IANA (https://www.iana.org/assignments/media-types/media-types.xhtml) - because of lightness purposes : it would require to include - all these MIME types in this librairy, which would weigh it - significantly. This kind of effort maybe is not worth for the use that - this function has in this entire librairy. - - More informations in the RFC specifications : - - https://tools.ietf.org/html/rfc2045 - - https://tools.ietf.org/html/rfc2046 - - https://tools.ietf.org/html/rfc7231#section-3.1.1.1 - - https://tools.ietf.org/html/rfc7231#section-3.1.1.5 -*/ -// Match simple MIME types -// NB : -// Subtype length must not exceed 100 characters. -// This rule does not comply to the RFC specs (what is the max length ?). - -var mimeTypeSimple = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i; // eslint-disable-line max-len -// Handle "charset" in "text/*" - -var mimeTypeText = /^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; // eslint-disable-line max-len -// Handle "boundary" in "multipart/*" - -var mimeTypeMultipart = /^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; // eslint-disable-line max-len - -function isMimeType(str) { - assertString(str); - return mimeTypeSimple.test(str) || mimeTypeText.test(str) || mimeTypeMultipart.test(str); -} - -var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; -var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; -var latDMS = /^(([1-8]?\d)\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|90\D+0\D+0)\D+[NSns]?$/i; -var longDMS = /^\s*([1-7]?\d{1,2}\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|180\D+0\D+0)\D+[EWew]?$/i; -var defaultLatLongOptions = { - checkDMS: false -}; -function isLatLong(str, options) { - assertString(str); - options = merge(options, defaultLatLongOptions); - if (!str.includes(',')) return false; - var pair = str.split(','); - if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false; - - if (options.checkDMS) { - return latDMS.test(pair[0]) && longDMS.test(pair[1]); - } - - return lat.test(pair[0]) && _long.test(pair[1]); -} - -var threeDigit = /^\d{3}$/; -var fourDigit = /^\d{4}$/; -var fiveDigit = /^\d{5}$/; -var sixDigit = /^\d{6}$/; -var patterns = { - AD: /^AD\d{3}$/, - AT: fourDigit, - AU: fourDigit, - AZ: /^AZ\d{4}$/, - BE: fourDigit, - BG: fourDigit, - BR: /^\d{5}-\d{3}$/, - BY: /2[1-4]{1}\d{4}$/, - CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i, - CH: fourDigit, - CN: /^(0[1-7]|1[012356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[1-5]|8[1345]|9[09])\d{4}$/, - CZ: /^\d{3}\s?\d{2}$/, - DE: fiveDigit, - DK: fourDigit, - DO: fiveDigit, - DZ: fiveDigit, - EE: fiveDigit, - ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/, - FI: fiveDigit, - 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}$)/, - HT: /^HT\d{4}$/, - HU: fourDigit, - ID: fiveDigit, - IE: /^(?!.*(?:o))[A-z]\d[\dw]\s\w{4}$/i, - IL: /^(\d{5}|\d{7})$/, - IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/, - IR: /\b(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}\b/, - IS: threeDigit, - IT: fiveDigit, - JP: /^\d{3}\-\d{4}$/, - KE: fiveDigit, - LI: /^(948[5-9]|949[0-7])$/, - LT: /^LT\-\d{5}$/, - LU: fourDigit, - LV: /^LV\-\d{4}$/, - MX: fiveDigit, - MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/, - MY: fiveDigit, - NL: /^\d{4}\s?[a-z]{2}$/i, - NO: fourDigit, - NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i, - NZ: fourDigit, - PL: /^\d{2}\-\d{3}$/, - PR: /^00[679]\d{2}([ -]\d{4})?$/, - PT: /^\d{4}\-\d{3}?$/, - RO: sixDigit, - RU: sixDigit, - SA: fiveDigit, - SE: /^[1-9]\d{2}\s?\d{2}$/, - SG: sixDigit, - SI: fourDigit, - SK: /^\d{3}\s?\d{2}$/, - TH: fiveDigit, - TN: fourDigit, - TW: /^\d{3}(\d{2})?$/, - UA: fiveDigit, - US: /^\d{5}(-\d{4})?$/, - ZA: fourDigit, - ZM: fiveDigit -}; -var locales$4 = Object.keys(patterns); -function isPostalCode(str, locale) { - assertString(str); - - if (locale in patterns) { - return patterns[locale].test(str); - } else if (locale === 'any') { - for (var key in patterns) { - // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes - // istanbul ignore else - if (patterns.hasOwnProperty(key)) { - var pattern = patterns[key]; - - if (pattern.test(str)) { - return true; - } - } - } - - return false; - } - - throw new Error("Invalid locale '".concat(locale, "'")); -} - -function ltrim(str, chars) { - assertString(str); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping - - var pattern = chars ? new RegExp("^[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+"), 'g') : /^\s+/g; - return str.replace(pattern, ''); -} - -function rtrim(str, chars) { - assertString(str); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping - - var pattern = chars ? new RegExp("[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+$"), 'g') : /\s+$/g; - return str.replace(pattern, ''); -} - -function trim(str, chars) { - return rtrim(ltrim(str, chars), chars); -} - -function escape(str) { - assertString(str); - return str.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(//g, '>').replace(/\//g, '/').replace(/\\/g, '\').replace(/`/g, '`'); -} - -function unescape(str) { - assertString(str); - return str.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, "'").replace(/</g, '<').replace(/>/g, '>').replace(///g, '/').replace(/\/g, '\\').replace(/`/g, '`'); -} - -function blacklist$1(str, chars) { - assertString(str); - return str.replace(new RegExp("[".concat(chars, "]+"), 'g'), ''); -} - -function stripLow(str, keep_new_lines) { - assertString(str); - var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F'; - return blacklist$1(str, chars); -} - -function whitelist(str, chars) { - assertString(str); - return str.replace(new RegExp("[^".concat(chars, "]+"), 'g'), ''); -} - -function isWhitelisted(str, chars) { - assertString(str); - - for (var i = str.length - 1; i >= 0; i--) { - if (chars.indexOf(str[i]) === -1) { - return false; - } - } - - return true; -} - -var default_normalize_email_options = { - // The following options apply to all email addresses - // Lowercases the local part of the email address. - // Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024). - // The domain is always lowercased, as per RFC 1035 - all_lowercase: true, - // The following conversions are specific to GMail - // Lowercases the local part of the GMail address (known to be case-insensitive) - gmail_lowercase: true, - // Removes dots from the local part of the email address, as that's ignored by GMail - gmail_remove_dots: true, - // Removes the subaddress (e.g. "+foo") from the email address - gmail_remove_subaddress: true, - // Conversts the googlemail.com domain to gmail.com - gmail_convert_googlemaildotcom: true, - // The following conversions are specific to Outlook.com / Windows Live / Hotmail - // Lowercases the local part of the Outlook.com address (known to be case-insensitive) - outlookdotcom_lowercase: true, - // Removes the subaddress (e.g. "+foo") from the email address - outlookdotcom_remove_subaddress: true, - // The following conversions are specific to Yahoo - // Lowercases the local part of the Yahoo address (known to be case-insensitive) - yahoo_lowercase: true, - // Removes the subaddress (e.g. "-foo") from the email address - yahoo_remove_subaddress: true, - // The following conversions are specific to Yandex - // Lowercases the local part of the Yandex address (known to be case-insensitive) - yandex_lowercase: true, - // The following conversions are specific to iCloud - // Lowercases the local part of the iCloud address (known to be case-insensitive) - icloud_lowercase: true, - // Removes the subaddress (e.g. "+foo") from the email address - icloud_remove_subaddress: true -}; // List of domains used by iCloud - -var icloud_domains = ['icloud.com', 'me.com']; // List of domains used by Outlook.com and its predecessors -// This list is likely incomplete. -// Partial reference: -// https://blogs.office.com/2013/04/17/outlook-com-gets-two-step-verification-sign-in-by-alias-and-new-international-domains/ - -var outlookdotcom_domains = ['hotmail.at', 'hotmail.be', 'hotmail.ca', 'hotmail.cl', 'hotmail.co.il', 'hotmail.co.nz', 'hotmail.co.th', 'hotmail.co.uk', 'hotmail.com', 'hotmail.com.ar', 'hotmail.com.au', 'hotmail.com.br', 'hotmail.com.gr', 'hotmail.com.mx', 'hotmail.com.pe', 'hotmail.com.tr', 'hotmail.com.vn', 'hotmail.cz', 'hotmail.de', 'hotmail.dk', 'hotmail.es', 'hotmail.fr', 'hotmail.hu', 'hotmail.id', 'hotmail.ie', 'hotmail.in', 'hotmail.it', 'hotmail.jp', 'hotmail.kr', 'hotmail.lv', 'hotmail.my', 'hotmail.ph', 'hotmail.pt', 'hotmail.sa', 'hotmail.sg', 'hotmail.sk', 'live.be', 'live.co.uk', 'live.com', 'live.com.ar', 'live.com.mx', 'live.de', 'live.es', 'live.eu', 'live.fr', 'live.it', 'live.nl', 'msn.com', 'outlook.at', 'outlook.be', 'outlook.cl', 'outlook.co.il', 'outlook.co.nz', 'outlook.co.th', 'outlook.com', 'outlook.com.ar', 'outlook.com.au', 'outlook.com.br', 'outlook.com.gr', 'outlook.com.pe', 'outlook.com.tr', 'outlook.com.vn', 'outlook.cz', 'outlook.de', 'outlook.dk', 'outlook.es', 'outlook.fr', 'outlook.hu', 'outlook.id', 'outlook.ie', 'outlook.in', 'outlook.it', 'outlook.jp', 'outlook.kr', 'outlook.lv', 'outlook.my', 'outlook.ph', 'outlook.pt', 'outlook.sa', 'outlook.sg', 'outlook.sk', 'passport.com']; // List of domains used by Yahoo Mail -// This list is likely incomplete - -var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com']; // List of domains used by yandex.ru - -var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru']; // replace single dots, but not multiple consecutive dots - -function dotsReplacer(match) { - if (match.length > 1) { - return match; - } - - return ''; -} - -function normalizeEmail(email, options) { - options = merge(options, default_normalize_email_options); - var raw_parts = email.split('@'); - var domain = raw_parts.pop(); - var user = raw_parts.join('@'); - var parts = [user, domain]; // The domain is always lowercased, as it's case-insensitive per RFC 1035 - - parts[1] = parts[1].toLowerCase(); - - if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') { - // Address is GMail - if (options.gmail_remove_subaddress) { - parts[0] = parts[0].split('+')[0]; - } - - if (options.gmail_remove_dots) { - // this does not replace consecutive dots like example..email@gmail.com - parts[0] = parts[0].replace(/\.+/g, dotsReplacer); - } - - if (!parts[0].length) { - return false; - } - - if (options.all_lowercase || options.gmail_lowercase) { - parts[0] = parts[0].toLowerCase(); - } - - parts[1] = options.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1]; - } else if (icloud_domains.indexOf(parts[1]) >= 0) { - // Address is iCloud - if (options.icloud_remove_subaddress) { - parts[0] = parts[0].split('+')[0]; - } - - if (!parts[0].length) { - return false; - } - - if (options.all_lowercase || options.icloud_lowercase) { - parts[0] = parts[0].toLowerCase(); - } - } else if (outlookdotcom_domains.indexOf(parts[1]) >= 0) { - // Address is Outlook.com - if (options.outlookdotcom_remove_subaddress) { - parts[0] = parts[0].split('+')[0]; - } - - if (!parts[0].length) { - return false; - } - - if (options.all_lowercase || options.outlookdotcom_lowercase) { - parts[0] = parts[0].toLowerCase(); - } - } else if (yahoo_domains.indexOf(parts[1]) >= 0) { - // Address is Yahoo - if (options.yahoo_remove_subaddress) { - var components = parts[0].split('-'); - parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0]; - } - - if (!parts[0].length) { - return false; - } - - if (options.all_lowercase || options.yahoo_lowercase) { - parts[0] = parts[0].toLowerCase(); - } - } else if (yandex_domains.indexOf(parts[1]) >= 0) { - if (options.all_lowercase || options.yandex_lowercase) { - parts[0] = parts[0].toLowerCase(); - } - - parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preferred - } else if (options.all_lowercase) { - // Any other address - parts[0] = parts[0].toLowerCase(); - } - - return parts.join('@'); -} - -var charsetRegex = /^[^\s-_](?!.*?[-_]{2,})([a-z0-9-\\]{1,})[^\s]*[^-_\s]$/; -function isSlug(str) { - assertString(str); - return charsetRegex.test(str); -} - -var validators$1 = { - 'de-DE': function deDE(str) { - return /^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS|TR|TÜ|UM|PZ|TP|UE|UN|UH|MN|KK|VB|V|AE|PL|RC|VG|GW|PW|VR|VK|KB|WA|WT|BE|WM|WE|AP|MO|WW|FB|WZ|WI|WB|JE|WF|WO|W|WÜ|BL|Z|GC)[- ]?[A-Z]{1,2}[- ]?\d{1,4}|(AIC|FDB|ABG|SLN|SAW|KLZ|BUL|ESB|NAB|SUL|WST|ABI|AZE|BTF|KÖT|DKB|FEU|ROT|ALZ|SMÜ|WER|AUR|NOR|DÜW|BRK|HAB|TÖL|WOR|BAD|BAR|BER|BIW|EBS|KEM|MÜB|PEG|BGL|BGD|REI|WIL|BKS|BIR|WAT|BOR|BOH|BOT|BRB|BLK|HHM|NEB|NMB|WSF|LEO|HDL|WMS|WZL|BÜS|CHA|KÖZ|ROD|WÜM|CLP|NEC|COC|ZEL|COE|CUX|DAH|LDS|DEG|DEL|RSL|DLG|DGF|LAN|HEI|MED|DON|KIB|ROK|JÜL|MON|SLE|EBE|EIC|HIG|WBS|BIT|PRÜ|LIB|EMD|WIT|ERH|HÖS|ERZ|ANA|ASZ|MAB|MEK|STL|SZB|FDS|HCH|HOR|WOL|FRG|GRA|WOS|FRI|FFB|GAP|GER|BRL|CLZ|GTH|NOH|HGW|GRZ|LÖB|NOL|WSW|DUD|HMÜ|OHA|KRU|HAL|HAM|HBS|QLB|HVL|NAU|HAS|EBN|GEO|HOH|HDH|ERK|HER|WAN|HEF|ROF|HBN|ALF|HSK|USI|NAI|REH|SAN|KÜN|ÖHR|HOL|WAR|ARN|BRG|GNT|HOG|WOH|KEH|MAI|PAR|RID|ROL|KLE|GEL|KUS|KYF|ART|SDH|LDK|DIL|MAL|VIB|LER|BNA|GHA|GRM|MTL|WUR|LEV|LIF|STE|WEL|LIP|VAI|LUP|HGN|LBZ|LWL|PCH|STB|DAN|MKK|SLÜ|MSP|TBB|MGH|MTK|BIN|MSH|EIL|HET|SGH|BID|MYK|MSE|MST|MÜR|WRN|MEI|GRH|RIE|MZG|MIL|OBB|BED|FLÖ|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str); - }, - 'de-LI': function deLI(str) { - return /^FL[- ]?\d{1,5}[UZ]?$/.test(str); - }, - 'pt-PT': function ptPT(str) { - return /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str); - }, - 'sq-AL': function sqAL(str) { - return /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str); - } -}; -function isLicensePlate(str, locale) { - assertString(str); - - if (locale in validators$1) { - return validators$1[locale](str); - } else if (locale === 'any') { - for (var key in validators$1) { - if (validators$1.hasOwnProperty(key)) { - var validator = validators$1[key]; - - if (validator(str)) { - return true; - } - } - } - - return false; - } - - throw new Error("Invalid locale '".concat(locale, "'")); -} - -var upperCaseRegex = /^[A-Z]$/; -var lowerCaseRegex = /^[a-z]$/; -var numberRegex = /^[0-9]$/; -var symbolRegex = /^[-#!$%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/; -var defaultOptions = { - minLength: 8, - minLowercase: 1, - minUppercase: 1, - minNumbers: 1, - minSymbols: 1, - returnScore: false, - pointsPerUnique: 1, - pointsPerRepeat: 0.5, - pointsForContainingLower: 10, - pointsForContainingUpper: 10, - pointsForContainingNumber: 10, - pointsForContainingSymbol: 10 -}; -/* Counts number of occurrences of each char in a string - * could be moved to util/ ? -*/ - -function countChars(str) { - var result = {}; - Array.from(str).forEach(function (_char) { - var curVal = result[_char]; - - if (curVal) { - result[_char] += 1; - } else { - result[_char] = 1; - } - }); - return result; -} -/* Return information about a password */ - - -function analyzePassword(password) { - var charMap = countChars(password); - var analysis = { - length: password.length, - uniqueChars: Object.keys(charMap).length, - uppercaseCount: 0, - lowercaseCount: 0, - numberCount: 0, - symbolCount: 0 - }; - Object.keys(charMap).forEach(function (_char2) { - if (upperCaseRegex.test(_char2)) { - analysis.uppercaseCount += charMap[_char2]; - } else if (lowerCaseRegex.test(_char2)) { - analysis.lowercaseCount += charMap[_char2]; - } else if (numberRegex.test(_char2)) { - analysis.numberCount += charMap[_char2]; - } else if (symbolRegex.test(_char2)) { - analysis.symbolCount += charMap[_char2]; - } - }); - return analysis; -} - -function scorePassword(analysis, scoringOptions) { - var points = 0; - points += analysis.uniqueChars * scoringOptions.pointsPerUnique; - points += (analysis.length - analysis.uniqueChars) * scoringOptions.pointsPerRepeat; - - if (analysis.lowercaseCount > 0) { - points += scoringOptions.pointsForContainingLower; - } - - if (analysis.uppercaseCount > 0) { - points += scoringOptions.pointsForContainingUpper; - } - - if (analysis.numberCount > 0) { - points += scoringOptions.pointsForContainingNumber; - } - - if (analysis.symbolCount > 0) { - points += scoringOptions.pointsForContainingSymbol; - } - - return points; -} - -function isStrongPassword(str) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - assertString(str); - var analysis = analyzePassword(str); - options = merge(options || {}, defaultOptions); - - if (options.returnScore) { - return scorePassword(analysis, options); - } - - return analysis.length >= options.minLength && analysis.lowercaseCount >= options.minLowercase && analysis.uppercaseCount >= options.minUppercase && analysis.numberCount >= options.minNumbers && analysis.symbolCount >= options.minSymbols; -} - -var vatMatchers = { - GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/, - IT: /^(IT)?[0-9]{11}$/ -}; -function isVAT(str, countryCode) { - assertString(str); - assertString(countryCode); - - if (countryCode in vatMatchers) { - return vatMatchers[countryCode].test(str); - } - - throw new Error("Invalid country code: '".concat(countryCode, "'")); -} - -var version = '13.5.1'; -var validator = { - version: version, - toDate: toDate, - toFloat: toFloat, - toInt: toInt, - toBoolean: toBoolean, - equals: equals, - contains: contains, - matches: matches, - isEmail: isEmail, - isURL: isURL, - isMACAddress: isMACAddress, - isIP: isIP, - isIPRange: isIPRange, - isFQDN: isFQDN, - isBoolean: isBoolean, - isIBAN: isIBAN, - isBIC: isBIC, - isAlpha: isAlpha, - isAlphaLocales: locales$1, - isAlphanumeric: isAlphanumeric, - isAlphanumericLocales: locales$2, - isNumeric: isNumeric, - isPassportNumber: isPassportNumber, - isPort: isPort, - isLowercase: isLowercase, - isUppercase: isUppercase, - isAscii: isAscii, - isFullWidth: isFullWidth, - isHalfWidth: isHalfWidth, - isVariableWidth: isVariableWidth, - isMultibyte: isMultibyte, - isSemVer: isSemVer, - isSurrogatePair: isSurrogatePair, - isInt: isInt, - isIMEI: isIMEI, - isFloat: isFloat, - isFloatLocales: locales, - isDecimal: isDecimal, - isHexadecimal: isHexadecimal, - isOctal: isOctal, - isDivisibleBy: isDivisibleBy, - isHexColor: isHexColor, - isRgbColor: isRgbColor, - isHSL: isHSL, - isISRC: isISRC, - isMD5: isMD5, - isHash: isHash, - isJWT: isJWT, - isJSON: isJSON, - isEmpty: isEmpty, - isLength: isLength, - isLocale: isLocale, - isByteLength: isByteLength, - isUUID: isUUID, - isMongoId: isMongoId, - isAfter: isAfter, - isBefore: isBefore, - isIn: isIn, - isCreditCard: isCreditCard, - isIdentityCard: isIdentityCard, - isEAN: isEAN, - isISIN: isISIN, - isISBN: isISBN, - isISSN: isISSN, - isMobilePhone: isMobilePhone, - isMobilePhoneLocales: locales$3, - isPostalCode: isPostalCode, - isPostalCodeLocales: locales$4, - isEthereumAddress: isEthereumAddress, - isCurrency: isCurrency, - isBtcAddress: isBtcAddress, - isISO8601: isISO8601, - isRFC3339: isRFC3339, - isISO31661Alpha2: isISO31661Alpha2, - isISO31661Alpha3: isISO31661Alpha3, - isBase32: isBase32, - isBase58: isBase58, - isBase64: isBase64, - isDataURI: isDataURI, - isMagnetURI: isMagnetURI, - isMimeType: isMimeType, - isLatLong: isLatLong, - ltrim: ltrim, - rtrim: rtrim, - trim: trim, - escape: escape, - unescape: unescape, - stripLow: stripLow, - whitelist: whitelist, - blacklist: blacklist$1, - isWhitelisted: isWhitelisted, - normalizeEmail: normalizeEmail, - toString: toString, - isSlug: isSlug, - isStrongPassword: isStrongPassword, - isTaxID: isTaxID, - isDate: isDate, - isLicensePlate: isLicensePlate, - isVAT: isVAT -}; - -return validator; - -}))); diff --git a/validator.min.js b/validator.min.js deleted file mode 100644 index 33d746093..000000000 --- a/validator.min.js +++ /dev/null @@ -1,24 +0,0 @@ -/*! - * Copyright (c) 2018 Chris O'Hara - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * 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 i(t){return(i="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 u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}(t,e)||c(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)}o["fr-CA"]=o["fr-FR"],s["fr-CA"]=s["fr-FR"],o["pt-BR"]=o["pt-PT"],s["pt-BR"]=s["pt-PT"],l["pt-BR"]=l["pt-PT"],o["pl-Pl"]=o["pl-PL"],s["pl-Pl"]=s["pl-PL"],l["pl-Pl"]=l["pl-PL"],o["fa-AF"]=o.fa;var R=Object.keys(l);function Z(t){return L(t)?parseFloat(t):NaN}function M(t){return"object"===i(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function B(t,e){var r,n=0e)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,b=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,P=/^[a-z\d]+$/,U=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,w=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,y=/^([\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 K={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,validate_length:!0},W=/^\[([^\]]+)\](?::([0-9]+))?$/;function x(t,e){for(var r,n=0;n=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){o=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(o)throw i}}}}(function(t,e){for(var r=[],n=Math.min(t.length,e.length),i=0;i=e.min,i=!e.hasOwnProperty("max")||t<=e.max,a=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&i&&a&&e}var st=/^[0-9]{15}$/,ct=/^\d{2}-\d{6}-\d{6}-\d{1}$/;var lt=/^[\x00-\x7F]+$/;var ut=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var dt=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var ft=/[^\x00-\x7F]/;var At,$t,pt=($t="i",At=(At=["^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)","(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))","?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$"]).join(""),new RegExp(At,$t));var ht=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function gt(t,e){return t.some(function(t){return e===t})}var St={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},Et=["","-","+"];var mt=/^(0x|0h)?[0-9A-F]+$/i;function vt(t){return d(t),mt.test(t)}var It=/^(0o)?[0-7]+$/i;var Lt=/^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;var Rt=/^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/,Zt=/^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/,Mt=/^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/,Bt=/^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;var Ft=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i,Nt=/^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;var Ct=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var Dt={AD:/^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,AE:/^(AE[0-9]{2})\d{3}\d{16}$/,AL:/^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,AT:/^(AT[0-9]{2})\d{16}$/,AZ:/^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,BA:/^(BA[0-9]{2})\d{16}$/,BE:/^(BE[0-9]{2})\d{12}$/,BG:/^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,BH:/^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,BR:/^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,BY:/^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,CH:/^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,CR:/^(CR[0-9]{2})\d{18}$/,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}$/,DO:/^(DO[0-9]{2})[A-Z]{4}\d{20}$/,EE:/^(EE[0-9]{2})\d{16}$/,EG:/^(EG[0-9]{2})\d{25}$/,ES:/^(ES[0-9]{2})\d{20}$/,FI:/^(FI[0-9]{2})\d{14}$/,FO:/^(FO[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-Z0-9]{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}$/,GT:/^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,HR:/^(HR[0-9]{2})\d{17}$/,HU:/^(HU[0-9]{2})\d{24}$/,IE:/^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,IL:/^(IL[0-9]{2})\d{19}$/,IQ:/^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,IR:/^(IR[0-9]{2})0\d{2}0\d{18}$/,IS:/^(IS[0-9]{2})\d{22}$/,IT:/^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,JO:/^(JO[0-9]{2})[A-Z]{4}\d{22}$/,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}$/,LC:/^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,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-Z0-9]{20}$/,ME:/^(ME[0-9]{2})\d{18}$/,MK:/^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,MR:/^(MR[0-9]{2})\d{23}$/,MT:/^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,MU:/^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,NL:/^(NL[0-9]{2})[A-Z]{4}\d{10}$/,NO:/^(NO[0-9]{2})\d{11}$/,PK:/^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,PL:/^(PL[0-9]{2})\d{24}$/,PS:/^(PS[0-9]{2})[A-Z0-9]{4}\d{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}$/,RS:/^(RS[0-9]{2})\d{18}$/,SA:/^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,SC:/^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,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}$/,SV:/^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,TL:/^(TL[0-9]{2})\d{19}$/,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}$/,VA:/^(VA[0-9]{2})\d{18}$/,VG:/^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,XK:/^(XK[0-9]{2})\d{16}$/};var Tt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var Gt=/^[a-f0-9]{32}$/;var Ot={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 _t=/[^A-Z0-9+\/=]/i,Ht=/^[A-Z0-9_\-]*$/i,bt={urlSafe:!1};function Pt(t,e){d(t),e=B(e,bt);var r=t.length;if(e.urlSafe)return Ht.test(t);if(r%4!=0||_t.test(t))return!1;e=t.indexOf("=");return-1===e||e===r-1||e===r-2&&"="===t[r-1]}var Ut={allow_primitives:!1};var wt={ignore_whitespace:!1};var yt={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 Kt=/^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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 Wt={ES:function(t){d(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;t=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"][t%23])},IN:function(t){var r=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],n=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],t=t.trim();if(!/^[1-9]\d{3}\s?\d{4}\s?\d{4}$/.test(t))return!1;var i=0;return t.replace(/\s/g,"").split("").map(Number).reverse().forEach(function(t,e){i=r[i][n[e%8][t]]}),0===i},IT:function(t){return 9===t.length&&("CA00000AA"!==t&&-1new Date)&&(t.getFullYear()===e&&t.getMonth()===r-1&&t.getDate()===n)}function a(t){return function(t){for(var e=t.substring(0,17),r=0,n=0;n<17;n++)r+=parseInt(e.charAt(n),10)*parseInt(o[n],10);return s[r%11]}(t)===t.charAt(17).toUpperCase()}var e,r=["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"],o=["7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"],s=["1","0","X","9","8","7","6","5","4","3","2"];return!!/^\d{15}|(\d{17}(\d|x|X))$/.test(e=t)&&(15===e.length?function(t){var e=/^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;t="19".concat(t.substring(6,12));return!!(e=i(t))}:function(t){var e=/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(t);if(!e)return!1;var r=t.substring(0,2);if(!(e=n(r)))return!1;r=t.substring(6,14);return!!(e=i(r))&&a(t)})(e)},"zh-TW":function(t){var n={A:10,B:11,C:12,D:13,E:14,F:15,G:16,H:17,I:34,J:18,K:19,L:20,M:21,N:22,O:35,P:23,Q:24,R:25,S:26,T:27,U:28,V:29,W:32,X:30,Y:31,Z:33},t=t.trim().toUpperCase();return!!/^[A-Z][0-9]{9}$/.test(t)&&Array.from(t).reduce(function(t,e,r){if(0!==r)return 9===r?(10-t%10-Number(e))%10==0:t+Number(e)*(9-r);e=n[e];return e%10*9+Math.floor(e/10)},0)}};var xt=8,Yt=/^(\d{8}|\d{13})$/;function kt(r){var t=10-r.slice(0,-1).split("").map(function(t,e){return Number(t)*(t=r.length,e=e,t===xt?e%2==0?3:1:e%2==0?1:3)}).reduce(function(t,e){return t+e},0)%10;return t<10?t:0}var Vt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var zt=/^(?:[0-9]{9}X|[0-9]{10})$/,jt=/^(?:[0-9]{13})$/,Jt=[1,3];function Xt(t){for(var e=10,r=0;ra?"".concat(e-1):"".concat(e)).concat(r);else if(r="".concat(e-1).concat(r),a-parseInt(r,10)<100)return!1}if(60?,.\/ ]$/,je={minLength:8,minLowercase:1,minUppercase:1,minNumbers:1,minSymbols:1,returnScore:!1,pointsPerUnique:1,pointsPerRepeat:.5,pointsForContainingLower:10,pointsForContainingUpper:10,pointsForContainingNumber:10,pointsForContainingSymbol:10};function Je(t){var e,r,n=(e=t,r={},Array.from(e).forEach(function(t){r[t]?r[t]+=1:r[t]=1}),r),i={length:t.length,uniqueChars:Object.keys(n).length,uppercaseCount:0,lowercaseCount:0,numberCount:0,symbolCount:0};return Object.keys(n).forEach(function(t){Ye.test(t)?i.uppercaseCount+=n[t]:ke.test(t)?i.lowercaseCount+=n[t]:Ve.test(t)?i.numberCount+=n[t]:ze.test(t)&&(i.symbolCount+=n[t])}),i}var Xe={GB:/^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,IT:/^(IT)?[0-9]{11}$/};return{version:"13.5.1",toDate:a,toFloat:Z,toInt:function(t,e){return d(t),parseInt(t,e||10)},toBoolean:function(t,e){return d(t),e?"1"===t||/^true$/i.test(t):"0"!==t&&!/^false$/i.test(t)&&""!==t},equals:function(t,e){return d(t),t===e},contains:function(t,e,r){return d(t),(r=B(r,F)).ignoreCase?0<=t.toLowerCase().indexOf(M(e).toLowerCase()):0<=t.indexOf(M(e))},matches:function(t,e,r){return d(t),"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)},isEmail:function(t,e){if(d(t),(e=B(e,_)).require_display_name||e.allow_display_name){var r=t.match(H);if(r){var n=u(r,3),i=n[1];if(t=n[2],i.endsWith(" ")&&(i=i.substr(0,i.length-1)),!function(t){var e=t.match(/^"(.+)"$/i);if((t=e?e[1]:t).trim()){if(/[\.";<>]/.test(t)){if(!e)return;if(!(t.split('"').length===t.split('\\"').length))return}return 1}}(i))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=B(e,K)).validate_length&&2083<=t.length)return!1;var r,n,i,a=t.split("#");if(1<(a=(t=(a=(t=a.shift()).split("?")).shift()).split("://")).length){if(i=a.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;a[0]=t.substr(2)}}if(""===(t=a.join("://")))return!1;if(""===(t=(a=t.split("/")).shift())&&!e.require_host)return!0;if(1<(a=t.split("@")).length){if(e.disallow_auth)return!1;if(-1===(o=a.shift()).indexOf(":")||0<=o.indexOf(":")&&2/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return d(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return d(t),He(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return d(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:He,isWhitelisted:function(t,e){d(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=B(e,be);var r=t.split("@"),t=r.pop();if((r=[r.join("@"),t])[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(e.gmail_remove_subaddress&&(r[0]=r[0].split("+")[0]),e.gmail_remove_dots&&(r[0]=r[0].replace(/\.+/g,Ke)),!r[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(r[0]=r[0].toLowerCase()),r[1]=e.gmail_convert_googlemaildotcom?"gmail.com":r[1]}else if(0<=Pe.indexOf(r[1])){if(e.icloud_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=Ue.indexOf(r[1])){if(e.outlookdotcom_remove_subaddress&&(r[0]=r[0].split("+")[0]),!r[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(r[0]=r[0].toLowerCase())}else if(0<=we.indexOf(r[1])){if(e.yahoo_remove_subaddress&&(t=r[0].split("-"),r[0]=1=e.minLength&&i.lowercaseCount>=e.minLowercase&&i.uppercaseCount>=e.minUppercase&&i.numberCount>=e.minNumbers&&i.symbolCount>=e.minSymbols},isTaxID:function(t){var e=1 Date: Fri, 26 Feb 2021 18:03:53 +0300 Subject: [PATCH 014/113] chore: refactor code in isDataURI validator (#1556) * refactor code in isdatauri validator * Delete validator.js * Delete validator.min.js Co-authored-by: Sarhan Aissi --- src/lib/isDataURI.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/isDataURI.js b/src/lib/isDataURI.js index 2df26decb..01e43f70c 100644 --- a/src/lib/isDataURI.js +++ b/src/lib/isDataURI.js @@ -22,9 +22,10 @@ export default function isDataURI(str) { return false; } for (let i = 0; i < attributes.length; i++) { - if (i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') { - // ok - } else if (!validAttribute.test(attributes[i])) { + if ( + !(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && + !validAttribute.test(attributes[i]) + ) { return false; } } From ae9a311005e7a7b47301ae98cd4df9872a0e61c8 Mon Sep 17 00:00:00 2001 From: Sarhan Aissi Date: Fri, 26 Feb 2021 17:07:51 +0100 Subject: [PATCH 015/113] chore: add a more explanatory description to CI jobs (#1617) --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 588c6f310..efa41e11e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,17 +10,18 @@ jobs: strategy: matrix: node-version: [14, 12, 10, 8, 6] + name: Run tests on Node.js ${{ matrix.node-version }} steps: - name: Setup Node.js ${{ matrix.node-version }} uses: actions/setup-node@v2-beta with: node-version: ${{ matrix.node-version }} check-latest: true - - name: Checkout Repository + - name: Checkout repository uses: actions/checkout@v2 - - name: Install Dependencies + - name: Install dependencies run: npm install - - name: Run Tests + - name: Run tests run: npm test - if: matrix.node-version == 14 name: Generate coverage file From de489700b3161ea7adcaa9081bf03ee0bd9b1e3d Mon Sep 17 00:00:00 2001 From: Federico Ciardi Date: Fri, 26 Feb 2021 17:09:38 +0100 Subject: [PATCH 016/113] fix(isMacAddress): improve regexes and options (#1616) * fix(isMacAddress): improve Regexes * docs: update docs * Update src/lib/isMACAddress.js * Update src/lib/isMACAddress.js * Update test/validators.js * Update README.md --- README.md | 2 +- src/lib/isMACAddress.js | 17 ++++++++--------- test/validators.js | 6 ++++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index db6da2679..372b34e38 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Validator | Description **isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL']` or `any`) **isLocale(str)** | check if the string is a locale **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. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. +**isMACAddress(str)** | check if the string is a MAC address.

`options` is an object which defaults to `{no_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format diff --git a/src/lib/isMACAddress.js b/src/lib/isMACAddress.js index 458c72c64..8ffc8c254 100644 --- a/src/lib/isMACAddress.js +++ b/src/lib/isMACAddress.js @@ -1,19 +1,18 @@ import assertString from './util/assertString'; -const macAddress = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/; -const macAddressNoColons = /^([0-9a-fA-F]){12}$/; -const macAddressWithHyphen = /^([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])$/; -const macAddressWithSpaces = /^([0-9a-fA-F][0-9a-fA-F]\s){5}([0-9a-fA-F][0-9a-fA-F])$/; -const macAddressWithDots = /^([0-9a-fA-F]{4}).([0-9a-fA-F]{4}).([0-9a-fA-F]{4})$/; +const macAddress = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){4}([0-9a-fA-F]{2})$/; +const macAddressNoSeparators = /^([0-9a-fA-F]){12}$/; +const macAddressWithDots = /^([0-9a-fA-F]{4}\.){2}([0-9a-fA-F]{4})$/; export default function isMACAddress(str, options) { assertString(str); - if (options && options.no_colons) { - return macAddressNoColons.test(str); + /** + * @deprecated `no_colons` TODO: remove it in the next major + */ + if (options && (options.no_colons || options.no_separators)) { + return macAddressNoSeparators.test(str); } return macAddress.test(str) - || macAddressWithHyphen.test(str) - || macAddressWithSpaces.test(str) || macAddressWithDots.test(str); } diff --git a/test/validators.js b/test/validators.js index b9899b626..97be2e9f8 100644 --- a/test/validators.js +++ b/test/validators.js @@ -719,21 +719,23 @@ describe('Validators', () => { invalid: [ 'abc', '01:02:03:04:05', + '01:02:03:04:05:z0', '01:02:03:04::ab', '1:2:3:4:5:6', 'AB:CD:EF:GH:01:02', 'A9C5 D4 9F EB D3', '01-02 03:04 05 ab', '0102.03:04.05ab', + '900f/dffs/sdea', ], }); }); - it('should validate MAC addresses without colons', () => { + it('should validate MAC addresses without separator', () => { test({ validator: 'isMACAddress', args: [{ - no_colons: true, + no_separators: true, }], valid: [ 'abababababab', From 23311204bced77298657cbe23a00faf29787fcd5 Mon Sep 17 00:00:00 2001 From: Ahmad Sghaier Date: Sat, 27 Feb 2021 22:52:03 -0500 Subject: [PATCH 017/113] feat: added Libya Passport and Identity Number Validation (#1583) * Added Libya Passort and Identity Number Validation * Delete validator.js * Delete validator.min.js Co-authored-by: Sarhan Aissi --- README.md | 4 ++-- src/lib/isIdentityCard.js | 13 +++++++++++++ src/lib/isPassportNumber.js | 1 + test/validators.js | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 372b34e38..39ee6e97c 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIBAN(str)** | check if a string is a IBAN (International Bank Account Number). -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

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

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'NO', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.

`options` is an object which can contain the keys `allow_hyphens`. Defaults to first format . If allow_hyphens is set to true, the validator will validate the second format. **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). @@ -143,7 +143,7 @@ Validator | Description **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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. **isOctal(str)** | check if the string is a valid octal number. -**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. +**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 24f828ae8..c24054b68 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -119,6 +119,19 @@ const validators = { } return sum % 10 === 0; }, + 'ar-LY': (str) => { + // Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2 + const NIN = /^(1|2)\d{11}$/; + + // sanitize user input + const sanitized = str.trim(); + + // validate the data structure + if (!NIN.test(sanitized)) { + return false; + } + return true; + }, 'ar-TN': (str) => { const DNI = /^\d{8}$/; diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 8a7716f80..76fd0827e 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -39,6 +39,7 @@ const passportRegexByCountryCode = { LT: /^[A-Z0-9]{8}$/, // LITHUANIA LU: /^[A-Z0-9]{8}$/, // LUXEMBURG LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA + LY: /^[A-Z0-9]{8}$/, // LIBYA MT: /^\d{7}$/, // MALTA NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS PO: /^[A-Z]{2}\d{7}$/, // POLAND diff --git a/test/validators.js b/test/validators.js index 97be2e9f8..94ebcbcb0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2593,6 +2593,20 @@ describe('Validators', () => { ], }); + test({ + validator: 'isPassportNumber', + args: ['LY'], + valid: [ + 'P79JF34X', + 'RJ45H4V2', + ], + invalid: [ + 'P79JF34', + 'RJ45H4V2C', + 'RJ4-H4V2', + ], + }); + test({ validator: 'isPassportNumber', args: ['MT'], @@ -4463,6 +4477,24 @@ describe('Validators', () => { '336000842', ], }, + { + locale: 'ar-LY', + valid: [ + '119803455876', + '120024679875', + '219624876201', + '220103480657', + ], + invalid: [ + '987654320123', + '123-456-7890', + '012345678912', + '1234567890', + 'AFJBHUYTREWR', + 'C4V6B1X0M5T6', + '9876543210123', + ], + }, { locale: 'ar-TN', valid: [ From 6d87bfe20c542969e1c12a1f0c1f8979c3b97ff1 Mon Sep 17 00:00:00 2001 From: Federico Ciardi Date: Wed, 3 Mar 2021 11:49:47 +0100 Subject: [PATCH 018/113] fix(isSlug & rtrim): regex no longer exposed to ReDOS attacks (#1603) --- src/lib/isSlug.js | 2 +- src/lib/rtrim.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/isSlug.js b/src/lib/isSlug.js index da0193137..28b872a92 100644 --- a/src/lib/isSlug.js +++ b/src/lib/isSlug.js @@ -1,6 +1,6 @@ import assertString from './util/assertString'; -let charsetRegex = /^[^\s-_](?!.*?[-_]{2,})([a-z0-9-\\]{1,})[^\s]*[^-_\s]$/; +let charsetRegex = /^[^\s-_](?!.*?[-_]{2,})[a-z0-9-\\][^\s]*[^-_\s]$/; export default function isSlug(str) { assertString(str); diff --git a/src/lib/rtrim.js b/src/lib/rtrim.js index b53d23f57..d10aaa9de 100644 --- a/src/lib/rtrim.js +++ b/src/lib/rtrim.js @@ -3,6 +3,6 @@ import assertString from './util/assertString'; export default function rtrim(str, chars) { assertString(str); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping - const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /\s+$/g; + const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /(\s)+$/g; return str.replace(pattern, ''); } From 328dea0a31bb1804951e2d4f014c3273ab17a6c2 Mon Sep 17 00:00:00 2001 From: Federico Ciardi Date: Wed, 3 Mar 2021 11:52:29 +0100 Subject: [PATCH 019/113] chore: add `isSlug` test cases (#1602) * test: add `isSlug` test cases * fix: remove duplicate test case --- test/validators.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index 94ebcbcb0..d7f6b0a9f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10032,8 +10032,15 @@ describe('Validators', () => { it('should validate slug', () => { test({ validator: 'isSlug', - args: ['cs_67CZ'], - valid: ['cs-cz', 'cscz'], + valid: [ + 'foo', + 'foo-bar', + 'foo_bar', + 'foo-bar-foo', + 'foo-bar_foo', + 'foo-bar_foo*75-b4r-**_foo', + 'foo-bar_foo*75-b4r-**_foo-&&', + ], invalid: [ 'not-----------slug', '@#_$@', From 022b100af77af10c1e67678a2ebc33b63c3eea55 Mon Sep 17 00:00:00 2001 From: Prahalad Belavadi Date: Wed, 3 Mar 2021 16:23:59 +0530 Subject: [PATCH 020/113] chore(docs): rephrase sentence for grammatical correctness (#1620) Change Text from "Passing anything other than a string is an error." to "Passing anything other than a string will result in an error." --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 39ee6e97c..11bc1a368 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A library of string validators and sanitizers. **This library validates and sanitizes strings only.** If you're not sure if your input is a string, coerce it using `input + ''`. -Passing anything other than a string is an error. +Passing anything other than a string will result in an error. ## Installation and Usage From deb1d1ef79fd60dfc60e7894db345df51eb409ee Mon Sep 17 00:00:00 2001 From: Shubham Verma Date: Wed, 3 Mar 2021 16:32:48 +0530 Subject: [PATCH 021/113] feat(isEAN, isAlphanumeric): add support for EAN-14 and sAlphanumeric update (#1577) * added support for EAN-14 along with test case * feat(isAlphanumeric): added options(optional parameter) * Delete validator.min.js * Delete validator.js Co-authored-by: Sarhan Aissi --- README.md | 2 +- src/lib/isAlphanumeric.js | 18 +++++++++++++++-- src/lib/isEAN.js | 17 ++++++++++------ test/validators.js | 42 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 11bc1a368..ab5609ae0 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Validator | Description **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, options])** | 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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. -**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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', '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`. +**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. **isAscii(str)** | check if the string contains ASCII chars only. **isBase32(str)** | check if a string is base32 encoded. **isBase58(str)** | check if a string is base58 encoded. diff --git a/src/lib/isAlphanumeric.js b/src/lib/isAlphanumeric.js index 1b2481cea..b259ab908 100644 --- a/src/lib/isAlphanumeric.js +++ b/src/lib/isAlphanumeric.js @@ -1,8 +1,22 @@ import assertString from './util/assertString'; import { alphanumeric } from './alpha'; -export default function isAlphanumeric(str, locale = 'en-US') { - assertString(str); +export default function isAlphanumeric(_str, locale = 'en-US', options = {}) { + assertString(_str); + + let str = _str; + const { ignore } = options; + + if (ignore) { + if (ignore instanceof RegExp) { + str = str.replace(ignore, ''); + } else if (typeof ignore === 'string') { + str = str.replace(new RegExp(`[${ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&')}]`, 'g'), ''); // escape regex for ignore + } else { + throw new Error('ignore should be instance of a String or RegExp'); + } + } + if (locale in alphanumeric) { return alphanumeric[locale].test(str); } diff --git a/src/lib/isEAN.js b/src/lib/isEAN.js index 674e14ceb..968c385dd 100644 --- a/src/lib/isEAN.js +++ b/src/lib/isEAN.js @@ -3,20 +3,25 @@ * the thirteen-digit EAN-13, while the * less commonly used 8-digit EAN-8 barcode was * introduced for use on small packages. + * Also EAN/UCC-14 is used for Grouping of individual + * trade items above unit level(Intermediate, Carton or Pallet). + * For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/ * EAN consists of: * GS1 prefix, manufacturer code, product code and check digit * Reference: https://en.wikipedia.org/wiki/International_Article_Number + * Reference: https://www.gtin.info/ */ import assertString from './util/assertString'; /** - * Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13 - * and Regular Expression for valid EANs (EAN-8, EAN-13), - * with exact numberic matching of 8 or 13 digits [0-9] + * Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14 + * and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14), + * with exact numberic matching of 8 or 13 or 14 digits [0-9] */ const LENGTH_EAN_8 = 8; -const validEanRegex = /^(\d{8}|\d{13})$/; +const LENGTH_EAN_14 = 14; +const validEanRegex = /^(\d{8}|\d{13}|\d{14})$/; /** @@ -28,7 +33,7 @@ const validEanRegex = /^(\d{8}|\d{13})$/; * @return {number} */ function getPositionWeightThroughLengthAndIndex(length, index) { - if (length === LENGTH_EAN_8) { + if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) { return (index % 2 === 0) ? 3 : 1; } @@ -56,7 +61,7 @@ function calculateCheckDigit(ean) { /** * Check if string is valid EAN: - * Matches EAN-8/EAN-13 regex + * Matches EAN-8/EAN-13/EAN-14 regex * Has valid check digit. * * @param {string} str diff --git a/test/validators.js b/test/validators.js index d7f6b0a9f..34b6474e8 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1573,6 +1573,45 @@ describe('Validators', () => { }); }); + it('should validate alphanumeric string with ignored characters', () => { + test({ + validator: 'isAlphanumeric', + args: ['en-US', { ignore: '@_- ' }], // ignore [@ space _ -] + valid: [ + 'Hello@123', + 'this is a valid alphaNumeric string', + 'En-US @ alpha_numeric', + ], + invalid: [ + 'In*Valid', + 'hello$123', + '{invalid}', + ], + }); + + test({ + validator: 'isAlphanumeric', + args: ['en-US', { ignore: /[\s/-]/g }], // ignore [space -] + valid: [ + 'en-US', + 'this is a valid alphaNumeric string', + ], + invalid: [ + 'INVALID$ AlphaNum Str', + 'hello@123', + 'abc*123', + ], + }); + + test({ + validator: 'isAlphanumeric', + args: ['en-US', { ignore: 1234 }], // invalid ignore matcher (ignore should be instance of a String or RegExp) + error: [ + 'alpha', + ], + }); + }); + it('should validate defined english aliases', () => { test({ validator: 'isAlphanumeric', @@ -4716,6 +4755,9 @@ describe('Validators', () => { '9771234567003', '9783161484100', '73513537', + '00012345600012', + '10012345678902', + '20012345678909', ], invalid: [ '5901234123451', From 6262f6295b887c8231d41942ce7ecfb9b822b7f4 Mon Sep 17 00:00:00 2001 From: Renan Montebelo Date: Fri, 12 Mar 2021 03:46:19 -0600 Subject: [PATCH 022/113] chore: improving code coverage to 100% branches (#1624) * Improving code coverage to 100% branches * Improving code coverage for isStrongPassword --- src/lib/isLicensePlate.js | 9 ++++----- src/lib/isStrongPassword.js | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index c4b010d48..db182bf55 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -16,11 +16,10 @@ export default function isLicensePlate(str, locale) { return validators[locale](str); } else if (locale === 'any') { for (const key in validators) { - if (validators.hasOwnProperty(key)) { - const validator = validators[key]; - if (validator(str)) { - return true; - } + /* eslint guard-for-in: 0 */ + const validator = validators[key]; + if (validator(str)) { + return true; } } return false; diff --git a/src/lib/isStrongPassword.js b/src/lib/isStrongPassword.js index e18a7597b..28bb0637f 100644 --- a/src/lib/isStrongPassword.js +++ b/src/lib/isStrongPassword.js @@ -49,6 +49,7 @@ function analyzePassword(password) { symbolCount: 0, }; Object.keys(charMap).forEach((char) => { + /* istanbul ignore else */ if (upperCaseRegex.test(char)) { analysis.uppercaseCount += charMap[char]; } else if (lowerCaseRegex.test(char)) { From 418df05e8a096f85adf5041232d1b4183af34355 Mon Sep 17 00:00:00 2001 From: Sarhan Aissi Date: Fri, 12 Mar 2021 10:47:24 +0100 Subject: [PATCH 023/113] fix(isMobilePhone): prevent allowing landline numbers in es-CO (#1623) * fix(isMobilePhone): prevent validator from allowing landline numbers in es-CO locale * fix(isMobilePhone): prevent es-CO validator from allowing invalid number --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 68a19922e..207dae71b 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -56,7 +56,7 @@ const phones = { 'en-ZW': /^(\+263)[0-9]{9}$/, 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/, 'es-BO': /^(\+?591)?(6|7)\d{7}$/, - 'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[0-9]{1}\d{6}$/, + 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/, 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/, 'es-CR': /^(\+506)?[2-8]\d{7}$/, 'es-DO': /^(\+?1)?8[024]9\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 34b6474e8..d6d02c540 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6506,18 +6506,11 @@ describe('Validators', () => { valid: [ '+573003321235', '573003321235', - '579871235', '3003321235', '3213321235', '3103321235', - '3253321235', - '3321235', - '574321235', - '5784321235', - '5784321235', - '9821235', + '3243321235', '573011140876', - '0698345', ], invalid: [ '1234', @@ -6530,6 +6523,13 @@ describe('Validators', () => { '5703013347567', '069834567', '969834567', + '579871235', + '574321235', + '5784321235', + '5784321235', + '9821235', + '0698345', + '3321235', ], }, { From 3c771e8743f9941f1af917cc0212fd8511528649 Mon Sep 17 00:00:00 2001 From: mschunke <40691873+mschunke@users.noreply.github.com> Date: Fri, 12 Mar 2021 06:49:20 -0300 Subject: [PATCH 024/113] feat(pt-BR): tax id, passport and license plates (#1613) * feat(pt-BR): tax id, passport and license plates * delete compiled files * fix(tests): tests now covering 100% of code * fix(licenseplate): removed license plate pt-br * fix(readme): removed license plate changes --- README.md | 4 +- src/lib/isPassportNumber.js | 1 + src/lib/isTaxID.js | 89 +++++++++++++++++++++++++++++++++++++ test/validators.js | 28 ++++++++++++ 4 files changed, 120 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab5609ae0..cde507282 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ Validator | Description **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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. **isOctal(str)** | check if the string is a valid octal number. -**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. +**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. @@ -153,7 +153,7 @@ Validator | Description **isUppercase(str)** | check if the string is uppercase. **isSlug** | Check if the string is of type slug. `Options` allow a single hyphen between string. e.g. [`cn-cn`, `cn-c-c`] **isStrongPassword(str [, options])** | Check if a password is strong or not. Allows for custom requirements or scoring rules. If `returnScore` is true, then the function returns an integer score for the password rather than a boolean.
Default options:
`{ minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1, returnScore: false, pointsPerUnique: 1, pointsPerRepeat: 0.5, pointsForContainingLower: 10, pointsForContainingUpper: 10, pointsForContainingNumber: 10, pointsForContainingSymbol: 10 }` -**isTaxID(str, locale)** | Check if the given value is a valid Tax Identification Number. Default locale is `en-US`.

More info about exact TIN support can be found in `src/lib/isTaxID.js`

Supported locales: `[ 'bg-BG', 'cs-CZ', 'de-AT', 'de-DE', 'dk-DK', 'el-CY', 'el-GR', 'en-GB', 'en-IE', 'en-US', 'es-ES', 'et-EE', 'fi-FI', 'fr-BE', 'fr-FR', 'fr-LU', 'hr-HR', 'hu-HU', 'it-IT', 'lb-LU', 'lt-LT', 'lv-LV' 'mt-MT', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE' ]` +**isTaxID(str, locale)** | Check if the given value is a valid Tax Identification Number. Default locale is `en-US`.

More info about exact TIN support can be found in `src/lib/isTaxID.js`

Supported locales: `[ 'bg-BG', 'cs-CZ', 'de-AT', 'de-DE', 'dk-DK', 'el-CY', 'el-GR', 'en-GB', 'en-IE', 'en-US', 'es-ES', 'et-EE', 'fi-FI', 'fr-BE', 'fr-FR', 'fr-LU', 'hr-HR', 'hu-HU', 'it-IT', 'lb-LU', 'lt-LT', 'lv-LV' 'mt-MT', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE' ]` **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 }`.

require_protocol - if set as true isURL will return false if protocol is not present in the URL.
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
protocols - valid protocols can be modified with this option.
require_host - if set as false isURL will not check if host is present in the URL.
require_port - if set as true isURL will check if port is present in the URL.
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.
validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). **isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). **isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 76fd0827e..0c1582e57 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -13,6 +13,7 @@ const passportRegexByCountryCode = { AU: /^[A-Z]\d{7}$/, // AUSTRALIA BE: /^[A-Z]{2}\d{6}$/, // BELGIUM BG: /^\d{9}$/, // BULGARIA + BR: /^[A-Z]{2}\d{6}$/, // BRAZIL BY: /^[A-Z]{2}\d{7}$/, // BELARUS CA: /^[A-Z]{2}\d{6}$/, // CANADA CH: /^[A-Z]\d{7}$/, // SWITZERLAND diff --git a/src/lib/isTaxID.js b/src/lib/isTaxID.js index 90a0c2a96..f1ebae6d9 100644 --- a/src/lib/isTaxID.js +++ b/src/lib/isTaxID.js @@ -852,6 +852,93 @@ function plPlCheck(tin) { return checksum === parseInt(tin[10], 10); } +/* +* pt-BR validation function +* (Cadastro de Pessoas Físicas (CPF, persons) +* Cadastro Nacional de Pessoas Jurídicas (CNPJ, entities) +* Both inputs will be validated +*/ + +function ptBrCheck(tin) { + tin = tin.replace(/[^\d]+/g, ''); + if (tin === '') return false; + + if (tin.length === 11) { + let sum; + let ramainder; + sum = 0; + tin = tin.replace(/[^\d]+/g, ''); + + if ( // Reject known invalid CPFs + tin === '11111111111' || + tin === '22222222222' || + tin === '33333333333' || + tin === '44444444444' || + tin === '55555555555' || + tin === '66666666666' || + tin === '77777777777' || + tin === '88888888888' || + tin === '99999999999' || + tin === '00000000000' + ) return false; + + for (let i = 1; i <= 9; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i); + ramainder = (sum * 10) % 11; + if ((ramainder === 10) || (ramainder === 11)) ramainder = 0; + if (ramainder !== parseInt(tin.substring(9, 10), 10)) return false; + sum = 0; + + for (let i = 1; i <= 10; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (12 - i); + ramainder = (sum * 10) % 11; + if ((ramainder === 10) || (ramainder === 11)) ramainder = 0; + if (ramainder !== parseInt(tin.substring(10, 11), 10)) return false; + + return true; + } + + if (tin.length !== 14) { return false; } + + if ( // Reject know invalid CNPJs + tin === '00000000000000' || + tin === '11111111111111' || + tin === '22222222222222' || + tin === '33333333333333' || + tin === '44444444444444' || + tin === '55555555555555' || + tin === '66666666666666' || + tin === '77777777777777' || + tin === '88888888888888' || + tin === '99999999999999') { return false; } + + let length = tin.length - 2; + let identifiers = tin.substring(0, length); + let verificators = tin.substring(length); + let sum = 0; + let pos = length - 7; + + for (let i = length; i >= 1; i--) { + sum += identifiers.charAt(length - i) * pos; + pos -= 1; + if (pos < 2) { pos = 9; } + } + let result = sum % 11 < 2 ? 0 : 11 - (sum % 11); + if (result !== parseInt(verificators.charAt(0), 10)) { return false; } + + length += 1; + identifiers = tin.substring(0, length); + sum = 0; + pos = length - 7; + for (let i = length; i >= 1; i--) { + sum += identifiers.charAt(length - i) * pos; + pos -= 1; + if (pos < 2) { pos = 9; } + } + result = sum % 11 < 2 ? 0 : 11 - (sum % 11); + if (result !== parseInt(verificators.charAt(1), 10)) { return false; } + + return true; +} + /* * pt-PT validation function * (Número de identificação fiscal (NIF), persons/entities) @@ -1039,6 +1126,7 @@ const taxIdFormat = { 'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i, 'nl-NL': /^\d{9}$/, 'pl-PL': /^\d{10,11}$/, + 'pt-BR': /^\d{11,14}$/, 'pt-PT': /^\d{9}$/, 'ro-RO': /^\d{13}$/, 'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/, @@ -1076,6 +1164,7 @@ const taxIdCheck = { 'mt-MT': mtMtCheck, 'nl-NL': nlNlCheck, 'pl-PL': plPlCheck, + 'pt-BR': ptBrCheck, 'pt-PT': ptPtCheck, 'ro-RO': roRoCheck, 'sk-SK': skSkCheck, diff --git a/test/validators.js b/test/validators.js index d6d02c540..310cc8e63 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2289,6 +2289,18 @@ describe('Validators', () => { ], }); + test({ + validator: 'isPassportNumber', + args: ['BR'], + valid: [ + 'FZ973689', + 'GH231233', + ], + invalid: [ + 'ABX29332', + ], + }); + test({ validator: 'isPassportNumber', args: ['BY'], @@ -9965,6 +9977,22 @@ describe('Validators', () => { '2234567855', '02223013623'], }); + test({ + validator: 'isTaxID', + args: ['pt-BR'], + valid: [ + '35161990910', + '74407265027', + '05423994000172', + '11867044000130'], + invalid: [ + '170.691.440-72', + '01494282042', + '11111111111', + '94.592.973/0001-82', + '28592361000192', + '11111111111111'], + }); test({ validator: 'isTaxID', args: ['pt-PT'], From 7989e5bdf5b69527ffc603c22c606838b6d0e7f1 Mon Sep 17 00:00:00 2001 From: Renan Montebelo Date: Fri, 12 Mar 2021 03:55:41 -0600 Subject: [PATCH 025/113] feat(isLicensePlate): add support for pt-BR locale (#1588) * License Plate validators: pt-BR and mercosur * Removing mercosur as it's not an actual valid country locale --- README.md | 2 +- src/lib/isLicensePlate.js | 2 ++ test/validators.js | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cde507282..de3089d04 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ Validator | Description **isJWT(str)** | check if the string is valid JWT token. **isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.

`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format. **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. -**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL']` or `any`) +**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR'']` or `any`). **isLocale(str)** | check if the string is a locale **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_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index db182bf55..a28d66da8 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -8,6 +8,8 @@ const validators = { /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str), 'sq-AL': str => /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str), + 'pt-BR': str => + /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str), }; export default function isLicensePlate(str, locale) { diff --git a/test/validators.js b/test/validators.js index 310cc8e63..d7550b38c 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10403,6 +10403,28 @@ describe('Validators', () => { 'AAA 00 AAA', ], }); + test({ + validator: 'isLicensePlate', + args: ['pt-BR'], + valid: [ + 'ABC1234', + 'ABC 1234', + 'ABC-1234', + 'ABC1D23', + 'ABC1K23', + 'ABC1Z23', + 'ABC 1D23', + 'ABC-1D23', + ], + invalid: [ + '', + 'AA 0 A', + 'AAA 00 AAA', + 'ABCD123', + 'AB12345', + 'AB123DC', + ], + }); test({ validator: 'isLicensePlate', args: ['any'], From bb0dba625b214ca6b1a667fd0cd2f057a0a3c587 Mon Sep 17 00:00:00 2001 From: Ho Chin Chee Date: Fri, 12 Mar 2021 18:08:42 +0800 Subject: [PATCH 026/113] feat(isPassportNumber): add MY locale (#1574) * [feat] Malaysian Passport validation * Delete validator.js * Delete validator.min.js Co-authored-by: Sarhan Aissi --- README.md | 2 +- src/lib/isPassportNumber.js | 1 + test/validators.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de3089d04..3354576f1 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ Validator | Description **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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. **isOctal(str)** | check if the string is a valid octal number. -**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. +**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 0c1582e57..3572abdfe 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -42,6 +42,7 @@ const passportRegexByCountryCode = { LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA LY: /^[A-Z0-9]{8}$/, // LIBYA MT: /^\d{7}$/, // MALTA + MY: /^[AHK]\d{8}$/, // MALAYSIA NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS PO: /^[A-Z]{2}\d{7}$/, // POLAND PT: /^[A-Z]\d{6}$/, // PORTUGAL diff --git a/test/validators.js b/test/validators.js index d7550b38c..4a4180a8e 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2670,6 +2670,20 @@ describe('Validators', () => { ], }); + test({ + validator: 'isPassportNumber', + args: ['MY'], + valid: [ + 'A00000000', + 'H12345678', + 'K43143233', + ], + invalid: [ + 'A1234567', + 'C01234567', + ], + }); + test({ validator: 'isPassportNumber', args: ['NL'], From 63b61629187a732c3b3c8d89fe4cacad890cad99 Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Sun, 14 Mar 2021 15:33:52 +0300 Subject: [PATCH 027/113] chore: add gitter chatroom badge (#1592) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3354576f1..d86ed5d62 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![Downloads][downloads-image]][npm-url] [![Backers on Open Collective](https://opencollective.com/validatorjs/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/validatorjs/sponsors/badge.svg)](#sponsors) +[![Gitter](https://badges.gitter.im/validatorjs/community.svg)](https://gitter.im/validatorjs/community) A library of string validators and sanitizers. From a31c116b2a2dc85f469d185acc4e853a2f61fceb Mon Sep 17 00:00:00 2001 From: Liwei Date: Tue, 13 Apr 2021 15:55:41 +0800 Subject: [PATCH 028/113] fix: update isMobilePhone validation for en-SG (#1573) Co-authored-by: Li Liwei --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 207dae71b..ed1f6d277 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -46,7 +46,7 @@ const phones = { 'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/, 'en-PH': /^(09|\+639)\d{9}$/, 'en-RW': /^(\+?250|0)?[7]\d{8}$/, - 'en-SG': /^(\+65)?[689]\d{7}$/, + 'en-SG': /^(\+65)?[3689]\d{7}$/, 'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/, 'en-TZ': /^(\+?255|0)?[67]\d{8}$/, 'en-UG': /^(\+?256|0)?[7]\d{8}$/, diff --git a/test/validators.js b/test/validators.js index 4a4180a8e..168128c41 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6263,6 +6263,7 @@ describe('Validators', () => { { locale: 'en-SG', valid: [ + '32891278', '87654321', '98765432', '+6587654321', @@ -6270,6 +6271,7 @@ describe('Validators', () => { '+6565241234', ], invalid: [ + '332891231', '987654321', '876543219', '8765432', From 5d6db637e9b3e53d2eade920be2ba2df055bc58d Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Sat, 17 Apr 2021 15:07:32 +0200 Subject: [PATCH 029/113] feat(isIPRange): add support for IP version 4 or 6 (#1594) Co-authored-by: Emilien Escalle --- README.md | 2 +- src/lib/isIPRange.js | 28 +++++++++++++++-- test/validators.js | 72 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 97 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d86ed5d62..6b471fc43 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ Validator | Description **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). **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). +**isIPRange(str [, version])** | check if the string is an IP Range (version 4 or 6). **isISBN(str [, version])** | check if the string is an ISBN (version 10 or 13). **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.
`options` is an object which defaults to `{ strict: false, strictSeparator: false }`. If `strict` is true, date strings with invalid dates like `2009-02-29` will be invalid. If `strictSeparator` is true, date strings with date and time separated by anything other than a T will be invalid. diff --git a/src/lib/isIPRange.js b/src/lib/isIPRange.js index ffb4e1afa..5bb6916c5 100644 --- a/src/lib/isIPRange.js +++ b/src/lib/isIPRange.js @@ -1,9 +1,11 @@ import assertString from './util/assertString'; import isIP from './isIP'; -const subnetMaybe = /^\d{1,2}$/; +const subnetMaybe = /^\d{1,3}$/; +const v4Subnet = 32; +const v6Subnet = 128; -export default function isIPRange(str) { +export default function isIPRange(str, version = '') { assertString(str); const parts = str.split('/'); @@ -21,5 +23,25 @@ export default function isIPRange(str) { return false; } - return isIP(parts[0], 4) && parts[1] <= 32 && parts[1] >= 0; + const isValidIP = isIP(parts[0], version); + if (!isValidIP) { + return false; + } + + // Define valid subnet according to IP's version + let expectedSubnet = null; + switch (String(version)) { + case '4': + expectedSubnet = v4Subnet; + break; + + case '6': + expectedSubnet = v6Subnet; + break; + + default: + expectedSubnet = isIP(parts[0], '6') ? v6Subnet : v4Subnet; + } + + return parts[1] <= expectedSubnet && parts[1] >= 0; } diff --git a/test/validators.js b/test/validators.js index 168128c41..962a4bb8b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -872,18 +872,88 @@ describe('Validators', () => { '127.0.0.1/24', '0.0.0.0/0', '255.255.255.0/32', + '::/0', + '::/128', + '2001::/128', + '2001:800::/128', + '::ffff:127.0.0.1/128', ], invalid: [ + 'abc', '127.200.230.1/35', '127.200.230.1/-1', '1.1.1.1/011', - '::1/64', '1.1.1/24.1', '1.1.1.1/01', '1.1.1.1/1.1', '1.1.1.1/1.', '1.1.1.1/1/1', '1.1.1.1', + '::1', + '::1/164', + '2001::/240', + '2001::/-1', + '2001::/001', + '2001::/24.1', + '2001:db8:0000:1:1:1:1:1', + '::ffff:127.0.0.1', + ], + }); + test({ + validator: 'isIPRange', + args: [4], + valid: [ + '127.0.0.1/1', + '0.0.0.0/1', + '255.255.255.255/1', + '1.2.3.4/1', + '255.0.0.1/1', + '0.0.1.1/1', + ], + invalid: [ + 'abc', + '::1', + '2001:db8:0000:1:1:1:1:1', + '::ffff:127.0.0.1', + '137.132.10.01', + '0.256.0.256', + '255.256.255.256', + ], + }); + test({ + validator: 'isIPRange', + args: [6], + valid: [ + '::1/1', + '2001:db8:0000:1:1:1:1:1/1', + '::ffff:127.0.0.1/1', + ], + invalid: [ + 'abc', + '127.0.0.1', + '0.0.0.0', + '255.255.255.255', + '1.2.3.4', + '::ffff:287.0.0.1', + '::ffff:287.0.0.1/254', + '%', + 'fe80::1234%', + 'fe80::1234%1%3%4', + 'fe80%fe80%', + ], + }); + test({ + validator: 'isIPRange', + args: [10], + valid: [], + invalid: [ + 'abc', + '127.0.0.1/1', + '0.0.0.0/1', + '255.255.255.255/1', + '1.2.3.4/1', + '::1/1', + '2001:db8:0000:1:1:1:1:1/1', ], }); }); From 39830a9cbc3450bd4f649a53ab8aafda5a422db5 Mon Sep 17 00:00:00 2001 From: Muhammad Hussein Fattahizadeh Date: Sat, 17 Apr 2021 17:40:40 +0430 Subject: [PATCH 030/113] feat: IR passport and identityCard, respect .gitignore files (#1595) * feat: isLuhn, IR passport and identityCard, respect .gitignore files * Update test/validators.js Co-authored-by: Federico Ciardi * fix: rEADME.md * fix: remove isLuhn Co-authored-by: Federico Ciardi --- README.md | 4 ++-- src/lib/isIdentityCard.js | 19 ++++++++++++++++++ src/lib/isPassportNumber.js | 1 + test/validators.js | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6b471fc43..4b2ed2dd4 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIBAN(str)** | check if a string is a IBAN (International Bank Account Number). -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'NO', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'IR', 'NO', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.

`options` is an object which can contain the keys `allow_hyphens`. Defaults to first format . If allow_hyphens is set to true, the validator will validate the second format. **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). @@ -144,7 +144,7 @@ Validator | Description **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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. **isOctal(str)** | check if the string is a valid octal number. -**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. +**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index c24054b68..872ff1920 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -75,6 +75,25 @@ const validators = { return c === 0; }, + IR: (str) => { + if (!str.match(/^\d{10}$/)) return false; + str = (`0000${str}`).substr(str.length - 6); + + if (parseInt(str.substr(3, 6), 10) === 0) return false; + + const lastNumber = parseInt(str.substr(9, 1), 10); + let sum = 0; + + for (let i = 0; i < 9; i++) { + sum += parseInt(str.substr(i, 1), 10) * (10 - i); + } + + sum %= 11; + + return ( + (sum < 2 && lastNumber === sum) || (sum >= 2 && lastNumber === 11 - sum) + ); + }, IT: function IT(str) { if (str.length !== 9) return false; if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 3572abdfe..ceda6ff02 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -33,6 +33,7 @@ const passportRegexByCountryCode = { HU: /^[A-Z]{2}(\d{6}|\d{7})$/, // HUNGARY IE: /^[A-Z0-9]{2}\d{7}$/, // IRELAND IN: /^[A-Z]{1}-?\d{7}$/, // INDIA + IR: /^[A-Z]\d{8}$/, // IRAN IS: /^(A)\d{7}$/, // ICELAND IT: /^[A-Z0-9]{2}\d{7}$/, // ITALY JP: /^[A-Z]{2}\d{7}$/, // JAPAN diff --git a/test/validators.js b/test/validators.js index 962a4bb8b..171d1a89d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2623,6 +2623,21 @@ describe('Validators', () => { ], }); + test({ + validator: 'isPassportNumber', + args: ['IR'], + valid: [ + 'J97634522', + 'A01234567', + 'Z11977831', + ], + invalid: [ + 'A0123456', + 'A0123456Z', + '012345678', + ], + }); + test({ validator: 'isPassportNumber', args: ['IS'], @@ -4545,6 +4560,31 @@ describe('Validators', () => { 'X1234567L', ], }, + { + locale: 'IR', + valid: [ + '0499370899', + '0790419904', + '0084575948', + '0963695398', + '0684159414', + '0067749828', + '0650451252', + '1583250689', + '4032152314', + '0076229645', + '4271467685', + '0200203241', + ], + invalid: [ + '1260293040', + '0000000001', + '1999999999', + '9999999991', + 'AAAAAAAAAA', + '0684159415', + ], + }, { locale: 'IT', valid: [ From b65ddc5afcfc4a29050763517d6f664a4378cbc6 Mon Sep 17 00:00:00 2001 From: Bruce MacNaughton Date: Sat, 17 Apr 2021 06:32:27 -0700 Subject: [PATCH 031/113] fix: fix A-z ranges (#1625) A number of files contain ranges of [A-z] which allows the characters [\]^_\ and the back-tick character. Those have been replaced by [A-Za-z]. --- src/lib/isBIC.js | 11 ++++++++++- src/lib/isISO31661Alpha2.js | 5 +++-- src/lib/isLocale.js | 2 +- src/lib/isPostalCode.js | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib/isBIC.js b/src/lib/isBIC.js index 1420da69a..240bfe18b 100644 --- a/src/lib/isBIC.js +++ b/src/lib/isBIC.js @@ -1,8 +1,17 @@ import assertString from './util/assertString'; +import { CountryCodes } from './isISO31661Alpha2'; -const isBICReg = /^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/; +// https://en.wikipedia.org/wiki/ISO_9362 +const isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/; export default function isBIC(str) { assertString(str); + + // toUpperCase() should be removed when a new major version goes out that changes + // the regex to [A-Z] (per the spec). + if (CountryCodes.indexOf(str.slice(4, 6).toUpperCase()) < 0) { + return false; + } + return isBICReg.test(str); } diff --git a/src/lib/isISO31661Alpha2.js b/src/lib/isISO31661Alpha2.js index ee1c33a40..e91ae8717 100644 --- a/src/lib/isISO31661Alpha2.js +++ b/src/lib/isISO31661Alpha2.js @@ -1,5 +1,4 @@ import assertString from './util/assertString'; -import includes from './util/includes'; // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 const validISO31661Alpha2CountriesCodes = [ @@ -32,5 +31,7 @@ const validISO31661Alpha2CountriesCodes = [ export default function isISO31661Alpha2(str) { assertString(str); - return includes(validISO31661Alpha2CountriesCodes, str.toUpperCase()); + return validISO31661Alpha2CountriesCodes.indexOf(str.toUpperCase()) >= 0; } + +export const CountryCodes = validISO31661Alpha2CountriesCodes; diff --git a/src/lib/isLocale.js b/src/lib/isLocale.js index ab66e5c59..cacac8aec 100644 --- a/src/lib/isLocale.js +++ b/src/lib/isLocale.js @@ -1,6 +1,6 @@ import assertString from './util/assertString'; -const localeReg = /^[A-z]{2,4}([_-]([A-z]{4}|[\d]{3}))?([_-]([A-z]{2}|[\d]{3}))?$/; +const localeReg = /^[A-Za-z]{2,4}([_-]([A-Za-z]{4}|[\d]{3}))?([_-]([A-Za-z]{2}|[\d]{3}))?$/; export default function isLocale(str) { assertString(str); diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index 23b373497..6791db235 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -33,7 +33,7 @@ const patterns = { HT: /^HT\d{4}$/, HU: fourDigit, ID: fiveDigit, - IE: /^(?!.*(?:o))[A-z]\d[\dw]\s\w{4}$/i, + IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i, IL: /^(\d{5}|\d{7})$/, IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/, IR: /\b(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}\b/, From 67a200d08cd3b1aec5f78d3253b6b57f7d4f68ee Mon Sep 17 00:00:00 2001 From: Choi Sumin Date: Sat, 17 Apr 2021 22:35:41 +0900 Subject: [PATCH 032/113] feat(isPostalCode): add KR locale (#1628) KR - South Korea --- README.md | 2 +- src/lib/isPostalCode.js | 1 + test/validators.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b2ed2dd4..ab5ff55a4 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Validator | Description **isOctal(str)** | check if the string is a valid octal number. **isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). +**isPostalCode(str, locale)** | check if the string is a postal code,

(locale is one of `[ 'AD', 'AT', 'AU', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'KR', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. **isRgbColor(str [, includePercentValues])** | check if the string is a rgb or rgba color.

`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false. **isSemVer(str)** | check if the string is a Semantic Versioning Specification (SemVer). diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index 6791db235..915c27f2b 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -41,6 +41,7 @@ const patterns = { IT: fiveDigit, JP: /^\d{3}\-\d{4}$/, KE: fiveDigit, + KR: /^(\d{5}|\d{6})$/, LI: /^(948[5-9]|949[0-7])$/, LT: /^LT\-\d{5}$/, LU: fourDigit, diff --git a/test/validators.js b/test/validators.js index 171d1a89d..20179542a 100644 --- a/test/validators.js +++ b/test/validators.js @@ -9615,6 +9615,17 @@ describe('Validators', () => { 'ab1234', ], }, + { + locale: 'KR', + valid: [ + '17008', + '339012', + ], + invalid: [ + '1412347', + 'ab1234', + ], + }, ]; let allValid = []; From 2ef84e430495249ddbd241adc28a944b4986ff3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ognjen=20Jevremovi=C4=87?= Date: Sat, 17 Apr 2021 15:39:03 +0200 Subject: [PATCH 033/113] fix(isIP): validator patterns for IPv4 and IPv6 RegExp formats (#1632) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 ipv4/ipv6 validators Provide a more strict regular expression patterns for ipv4 and ipv6 formats. ✅ Closes: #1626 * test: 💍 ipv4/ipv6 unit tests Extend upon existing IP validator unit test, valid examples. Provide IPv6 test addresses including `%`. ✅ Closes: #1626 --- src/lib/isIP.js | 91 +++++++++++----------------------------------- test/validators.js | 26 +++++++++++++ 2 files changed, 47 insertions(+), 70 deletions(-) diff --git a/src/lib/isIP.js b/src/lib/isIP.js index a9a805781..25856cae0 100644 --- a/src/lib/isIP.js +++ b/src/lib/isIP.js @@ -28,86 +28,37 @@ import assertString from './util/assertString'; where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs to the 5th link, and "interface10" belongs to the 10th organization. * * */ -const ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; -const ipv6Block = /^[0-9A-F]{1,4}$/i; +const IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'; +const IPv4AddressFormat = `(${IPv4SegmentFormat}[.]){3}${IPv4SegmentFormat}`; +const IPv4AddressRegExp = new RegExp(`^${IPv4AddressFormat}$`); + +const IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})'; +const IPv6AddressRegExp = new RegExp('^(' + + `(?:${IPv6SegmentFormat}:){7}(?:${IPv6SegmentFormat}|:)|` + + `(?:${IPv6SegmentFormat}:){6}(?:${IPv4AddressFormat}|:${IPv6SegmentFormat}|:)|` + + `(?:${IPv6SegmentFormat}:){5}(?::${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,2}|:)|` + + `(?:${IPv6SegmentFormat}:){4}(?:(:${IPv6SegmentFormat}){0,1}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,3}|:)|` + + `(?:${IPv6SegmentFormat}:){3}(?:(:${IPv6SegmentFormat}){0,2}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,4}|:)|` + + `(?:${IPv6SegmentFormat}:){2}(?:(:${IPv6SegmentFormat}){0,3}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,5}|:)|` + + `(?:${IPv6SegmentFormat}:){1}(?:(:${IPv6SegmentFormat}){0,4}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,6}|:)|` + + `(?::((?::${IPv6SegmentFormat}){0,5}:${IPv4AddressFormat}|(?::${IPv6SegmentFormat}){1,7}|:))` + + ')(%[0-9a-zA-Z-.:]{1,})?$'); export default function isIP(str, version = '') { assertString(str); version = String(version); if (!version) { return isIP(str, 4) || isIP(str, 6); - } else if (version === '4') { - if (!ipv4Maybe.test(str)) { + } + if (version === '4') { + if (!IPv4AddressRegExp.test(str)) { return false; } const parts = str.split('.').sort((a, b) => a - b); return parts[3] <= 255; - } else if (version === '6') { - let addressAndZone = [str]; - // ipv6 addresses could have scoped architecture - // according to https://tools.ietf.org/html/rfc4007#section-11 - if (str.includes('%')) { - addressAndZone = str.split('%'); - if (addressAndZone.length !== 2) { - // it must be just two parts - return false; - } - if (!addressAndZone[0].includes(':')) { - // the first part must be the address - return false; - } - - if (addressAndZone[1] === '') { - // the second part must not be empty - return false; - } - } - - const blocks = addressAndZone[0].split(':'); - let foundOmissionBlock = false; // marker to indicate :: - - // At least some OS accept the last 32 bits of an IPv6 address - // (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says - // that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses, - // and '::a.b.c.d' is deprecated, but also valid. - const foundIPv4TransitionBlock = isIP(blocks[blocks.length - 1], 4); - const expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8; - - if (blocks.length > expectedNumberOfBlocks) { - return false; - } - // initial or final :: - if (str === '::') { - return true; - } else if (str.substr(0, 2) === '::') { - blocks.shift(); - blocks.shift(); - foundOmissionBlock = true; - } else if (str.substr(str.length - 2) === '::') { - blocks.pop(); - blocks.pop(); - foundOmissionBlock = true; - } - - for (let i = 0; i < blocks.length; ++i) { - // test for a :: which can not be at the string start/end - // since those cases have been handled above - if (blocks[i] === '' && i > 0 && i < blocks.length - 1) { - if (foundOmissionBlock) { - return false; // multiple :: in address - } - foundOmissionBlock = true; - } else if (foundIPv4TransitionBlock && i === blocks.length - 1) { - // it has been checked before that the last - // block is a valid IPv4 address - } else if (!ipv6Block.test(blocks[i])) { - return false; - } - } - if (foundOmissionBlock) { - return blocks.length >= 1; - } - return blocks.length === expectedNumberOfBlocks; + } + if (version === '6') { + return !!IPv6AddressRegExp.test(str); } return false; } diff --git a/test/validators.js b/test/validators.js index 20179542a..2befa37d0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -771,6 +771,7 @@ describe('Validators', () => { '1.2.3.4', '::1', '2001:db8:0000:1:1:1:1:1', + '2001:db8:3:4::192.0.2.33', '2001:41d0:2:a141::1', '::ffff:127.0.0.1', '::0000', @@ -779,8 +780,33 @@ describe('Validators', () => { '1111:1:1:1:1:1:1:1', 'fe80::a6db:30ff:fe98:e946', '::', + '::8', '::ffff:127.0.0.1', + '::ffff:255.255.255.255', + '::ffff:0:255.255.255.255', + '::2:3:4:5:6:7:8', + '::255.255.255.255', '0:0:0:0:0:ffff:127.0.0.1', + '1:2:3:4:5:6:7::', + '1:2:3:4:5:6::8', + '1::7:8', + '1:2:3:4:5::7:8', + '1:2:3:4:5::8', + '1::6:7:8', + '1:2:3:4::6:7:8', + '1:2:3:4::8', + '1::5:6:7:8', + '1:2:3::5:6:7:8', + '1:2:3::8', + '1::4:5:6:7:8', + '1:2::4:5:6:7:8', + '1:2::8', + '1::3:4:5:6:7:8', + '1::8', + 'fe80::7:8%eth0', + 'fe80::7:8%1', + '64:ff9b::192.0.2.33', + '0:0:0:0:0:0:10.0.0.1', ], invalid: [ 'abc', From c33fca687d2f1c9b809574c276838593abc40882 Mon Sep 17 00:00:00 2001 From: Bruce MacNaughton Date: Sat, 17 Apr 2021 06:42:40 -0700 Subject: [PATCH 034/113] fix(isISIN): optimization (#1633) * optimize isISIN speed + gc * add aapl ISIN * comment and reference --- src/lib/isISIN.js | 57 ++++++++++++++++++++++++++++++++-------------- test/validators.js | 1 + 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/lib/isISIN.js b/src/lib/isISIN.js index 4576b684c..a6f6fa645 100644 --- a/src/lib/isISIN.js +++ b/src/lib/isISIN.js @@ -2,6 +2,12 @@ import assertString from './util/assertString'; const isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/; +// this link details how the check digit is calculated: +// https://www.isin.org/isin-format/. it is a little bit +// odd in that it works with digits, not numbers. in order +// to make only one pass through the ISIN characters, the +// each alpha character is handled as 2 characters within +// the loop. export default function isISIN(str) { assertString(str); @@ -9,27 +15,44 @@ export default function isISIN(str) { return false; } - const checksumStr = str.replace(/[A-Z]/g, character => (parseInt(character, 36))); - + let double = true; let sum = 0; - let digit; - let tmpNum; - let shouldDouble = true; - for (let i = checksumStr.length - 2; i >= 0; i--) { - digit = checksumStr.substring(i, (i + 1)); - tmpNum = parseInt(digit, 10); - if (shouldDouble) { - tmpNum *= 2; - if (tmpNum >= 10) { - sum += tmpNum + 1; - } else { - sum += tmpNum; + // convert values + for (let i = str.length - 2; i >= 0; i--) { + if (str[i] >= 'A' && str[i] <= 'Z') { + const value = str[i].charCodeAt(0) - 55; + const lo = value % 10; + const hi = Math.trunc(value / 10); + // letters have two digits, so handle the low order + // and high order digits separately. + for (const digit of [lo, hi]) { + if (double) { + if (digit >= 5) { + sum += 1 + ((digit - 5) * 2); + } else { + sum += digit * 2; + } + } else { + sum += digit; + } + double = !double; } } else { - sum += tmpNum; + const digit = str[i].charCodeAt(0) - '0'.charCodeAt(0); + if (double) { + if (digit >= 5) { + sum += 1 + ((digit - 5) * 2); + } else { + sum += digit * 2; + } + } else { + sum += digit; + } + double = !double; } - shouldDouble = !shouldDouble; } - return parseInt(str.substr(str.length - 1), 10) === (10000 - sum) % 10; + const check = (Math.trunc(((sum + 9) / 10)) * 10) - sum; + + return +str[str.length - 1] === check; } diff --git a/test/validators.js b/test/validators.js index 2befa37d0..1f92e1480 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4845,6 +4845,7 @@ describe('Validators', () => { 'GB0001411924', 'DE000WCH8881', 'PLLWBGD00016', + 'US0378331005', ], invalid: [ 'DE000BAY0018', From d006e08472cc5981962fa6b098a392a54fc42608 Mon Sep 17 00:00:00 2001 From: ankorGH Date: Sat, 17 Apr 2021 13:44:05 +0000 Subject: [PATCH 035/113] fix(isMobilePhone): add support for new networks codes in GH (#1635) --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index ed1f6d277..a551ba095 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -33,7 +33,7 @@ const phones = { 'en-AU': /^(\+?61|0)4\d{8}$/, 'en-GB': /^(\+?44|0)7\d{9}$/, 'en-GG': /^(\+?44|0)1481\d{6}$/, - 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/, + 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28|55|59)\d{7}$/, 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/, 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/, 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 1f92e1480..f30f9caf6 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6011,6 +6011,8 @@ describe('Validators', () => { '+233562345671', '+233232345671', '+233282345671', + '+233592349493', + '0550298219', ], invalid: [ '082123', From 615547fad1251202ce7b543052e25c88f9b2e381 Mon Sep 17 00:00:00 2001 From: Anton Lukichev Date: Sat, 17 Apr 2021 16:45:51 +0300 Subject: [PATCH 036/113] feat(isMobilePhone): add Latvia lv-LV locale (#1638) --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab5ff55a4..05b353032 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'lv-LV', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index a551ba095..1b2388fdd 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -89,6 +89,7 @@ const phones = { '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}$/, + 'lv-LV': /^(\+?371)2\d{7}$/, 'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/, 'nb-NO': /^(\+?47)?[49]\d{7}$/, 'ne-NP': /^(\+?977)?9[78]\d{8}$/, diff --git a/test/validators.js b/test/validators.js index f30f9caf6..dab91650f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7660,6 +7660,20 @@ describe('Validators', () => { 'NotANumber', ], }, + { + locale: 'lv-LV', + valid: [ + '+37121234567', + '37121234567', + ], + invalid: [ + '+37201234567', + '+3754321', + '3712123456', + '+371212345678', + 'NotANumber', + ], + }, ]; let allValid = []; From b82f4f2371242cf2cd7c28cbb317fb5695cef902 Mon Sep 17 00:00:00 2001 From: Federico Ciardi Date: Sat, 17 Apr 2021 15:47:15 +0200 Subject: [PATCH 037/113] fix(docs): typo in README.md (#1640) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 05b353032..b901111b4 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Validator | Description **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', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa', 'fa-AF', 'fa-IR', 'fr-FR', 'fr-CA', 'hu-HU', 'id-ID', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pl-Pl', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN']`.
**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. **isEAN(str)** | check if the string is an EAN (European Article Number). -**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, blacklisted_chars: '' }`. 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 `ignore_max_length` is set to true, the validator will not check for the standard max length of an email. 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. If `blacklisted_chars` recieves a string,then the validator will reject emails that include any of the characters in the string, in the name part. +**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, blacklisted_chars: '' }`. 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 `ignore_max_length` is set to true, the validator will not check for the standard max length of an email. 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. If `blacklisted_chars` receives a string, then the validator will reject emails that include any of the characters in the string, in the name part. **isEmpty(str [, options])** | check if the string has a length of zero.

`options` is an object which defaults to `{ ignore_whitespace:false }`. **isEthereumAddress(str)** | check if the string is an [Ethereum](https://ethereum.org/) address using basic regex. Does not validate address checksums. **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-CA', '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`. From 9ee1b6baa52e1f6cc88fd695f34b80f26cfaa12f Mon Sep 17 00:00:00 2001 From: Akira <1225658998@qq.com> Date: Sat, 17 Apr 2021 21:50:13 +0800 Subject: [PATCH 038/113] fix(isMobilePhone): update china zh-CN locale (#1642) --- src/lib/isMobilePhone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 1b2388fdd..903236222 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -112,7 +112,7 @@ const phones = { 'uk-UA': /^(\+?38|8)?0\d{9}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, 'vi-VN': /^(\+?84|0)((3([2-9]))|(5([2689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, - 'zh-CN': /^((\+|00)86)?1([3568][0-9]|4[579]|6[67]|7[01235678]|9[012356789])[0-9]{8}$/, + 'zh-CN': /^((\+|00)86)?1([3456789][0-9]|4[579]|6[67]|7[01235678]|9[012356789])[0-9]{8}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, }; /* eslint-enable max-len */ From 05ceb18cfda13c4c14f570edb08978eabd971457 Mon Sep 17 00:00:00 2001 From: Jeremy Buchmann Date: Sat, 17 Apr 2021 15:52:09 +0200 Subject: [PATCH 039/113] isURL(): Allow URLs to have only a username in the userinfo subcomponent (#1644) * Added some missing options to the isURL() docs * Allow URLs to have a userinfo section with only a username The 'userinfo' part of a URL may, according to RFC 1738, contain only a username followed by an '@' sign. The previous behavior of the isURL() function would return false if the userinfo section did not have a colon. In addition to the change in the function, tests have been added to ensure the following exmaples are considered valid: - http://user@example.com - http://user:@example.com - http://user:pass@example.com The following are considered not valid: - http://@example.com - http://:@example.com - http://:example.com As a practical example, Sentry (https://github.com/getsentry/sentry) uses a format like http://9b9cd2ef993c1fd9c14cbb88466@example.com/10 for it's DSNs (which are just URLs). --- README.md | 8 ++++---- src/lib/isURL.js | 5 ++++- test/validators.js | 23 +++++++++++++++++++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b901111b4..a9785222a 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Here is a list of the validators currently available. Validator | Description --------------------------------------- | -------------------------------------- -**contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false}`.
`ignoreCase` specified whether the case of the substring be same or not. +**contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false}`.
`ignoreCase` specified whether the case of the substring be same or not. **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, options])** | 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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. @@ -130,9 +130,9 @@ Validator | Description **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. **isJSON(str [, options])** | check if the string is valid JSON (note: uses JSON.parse).

`options` is an object which defaults to `{ allow_primitives: false }`. If `allow_primitives` is true, the primitives 'true', 'false' and 'null' are accepted as valid JSON values. **isJWT(str)** | check if the string is valid JWT token. -**isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.

`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format. +**isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.

`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format. **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. -**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR'']` or `any`). +**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR'']` or `any`). **isLocale(str)** | check if the string is a locale **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_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. @@ -155,7 +155,7 @@ Validator | Description **isSlug** | Check if the string is of type slug. `Options` allow a single hyphen between string. e.g. [`cn-cn`, `cn-c-c`] **isStrongPassword(str [, options])** | Check if a password is strong or not. Allows for custom requirements or scoring rules. If `returnScore` is true, then the function returns an integer score for the password rather than a boolean.
Default options:
`{ minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1, returnScore: false, pointsPerUnique: 1, pointsPerRepeat: 0.5, pointsForContainingLower: 10, pointsForContainingUpper: 10, pointsForContainingNumber: 10, pointsForContainingSymbol: 10 }` **isTaxID(str, locale)** | Check if the given value is a valid Tax Identification Number. Default locale is `en-US`.

More info about exact TIN support can be found in `src/lib/isTaxID.js`

Supported locales: `[ 'bg-BG', 'cs-CZ', 'de-AT', 'de-DE', 'dk-DK', 'el-CY', 'el-GR', 'en-GB', 'en-IE', 'en-US', 'es-ES', 'et-EE', 'fi-FI', 'fr-BE', 'fr-FR', 'fr-LU', 'hr-HR', 'hu-HU', 'it-IT', 'lb-LU', 'lt-LT', 'lv-LV' 'mt-MT', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE' ]` -**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 }`.

require_protocol - if set as true isURL will return false if protocol is not present in the URL.
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
protocols - valid protocols can be modified with this option.
require_host - if set as false isURL will not check if host is present in the URL.
require_port - if set as true isURL will check if port is present in the URL.
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.
validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). +**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_port: false, 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, validate_length: true }`.

require_protocol - if set as true isURL will return false if protocol is not present in the URL.
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
protocols - valid protocols can be modified with this option.
require_host - if set as false isURL will not check if host is present in the URL.
require_port - if set as true isURL will check if port is present in the URL.
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.
validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). **isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). **isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. **isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

Available country codes: `[ 'GB', 'IT' ]`. diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 6fe5651e5..4306e5deb 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -101,8 +101,11 @@ export default function isURL(url, options) { if (options.disallow_auth) { return false; } + if (split[0] === '' || split[0].substr(0, 1) === ':') { + return false; + } auth = split.shift(); - if (auth.indexOf(':') === -1 || (auth.indexOf(':') >= 0 && auth.split(':').length > 2)) { + if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) { return false; } } diff --git a/test/validators.js b/test/validators.js index dab91650f..52146fa82 100644 --- a/test/validators.js +++ b/test/validators.js @@ -350,6 +350,7 @@ describe('Validators', () => { 'http://www.foobar.com/~foobar', 'http://user:pass@www.foobar.com/', 'http://user:@www.foobar.com/', + 'http://user@www.foobar.com', 'http://127.0.0.1/', 'http://10.0.0.0/', 'http://189.123.14.13/', @@ -374,7 +375,6 @@ describe('Validators', () => { 'http://[::FFFF:129.144.52.38]:80/index.html', 'http://[2010:836B:4179::836B:4179]', 'http://example.com/example.json#/foo/bar', - 'http://user:@www.foobar.com', 'http://1337.com', ], invalid: [ @@ -405,6 +405,8 @@ describe('Validators', () => { 'http://lol: @foobar.com/', 'http://www.foo_bar.com/', 'http://www.foobar.com/\t', + 'http://@foobar.com', + 'http://:@foobar.com', 'http://\n@www.foobar.com/', '', `http://foobar.com/${new Array(2083).join('f')}`, @@ -416,7 +418,6 @@ describe('Validators', () => { '////foobar.com', 'http:////foobar.com', 'https://example.com/foo//', - 'myemail@mail.com', ], }); }); @@ -668,6 +669,24 @@ describe('Validators', () => { }); }); + it('should accept urls containing authentication information', () => { + test({ + validator: 'isURL', + args: [{ disallow_auth: false }], + valid: [ + 'user@example.com', + 'user:@example.com', + 'user:password@example.com', + ], + invalid: [ + 'user:user:password@example.com', + '@example.com', + ':@example.com', + ':example.com', + ], + }); + }); + it('should allow user to skip URL length validation', () => { test({ validator: 'isURL', From 3f70b8e5eb705ec2a452dcda3267a1c6ba8e1e3d Mon Sep 17 00:00:00 2001 From: Salmento Chitlango <49094323+salmento@users.noreply.github.com> Date: Sun, 18 Apr 2021 17:48:07 +0200 Subject: [PATCH 040/113] feat(isPassportNumber, isIBAN, isMobilePhone): add Mozambique locale (#1604) * added instruction into isPassportNumber to validate Mozambican passport number. * Add to (isMobilePhone) to validate numbers from Mozambique * Deleted validator.js and validator.min.js * docs: remove trailing space from isPassportNumber * isIBAM Mozambique Co-authored-by: Sarhan Aissi --- README.md | 6 ++-- src/lib/isIBAN.js | 1 + src/lib/isMobilePhone.js | 1 + src/lib/isPassportNumber.js | 1 + test/validators.js | 60 +++++++++++++++++++++++++++++++++++-- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a9785222a..965973930 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIBAN(str)** | check if a string is a IBAN (International Bank Account Number). -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'IR', 'NO', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.

`options` is an object which can contain the keys `allow_hyphens`. Defaults to first format . If allow_hyphens is set to true, the validator will validate the second format. **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). @@ -139,12 +139,12 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'lv-LV', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. **isOctal(str)** | check if the string is a valid octal number. -**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. +**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'MZ', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'KR', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. diff --git a/src/lib/isIBAN.js b/src/lib/isIBAN.js index 77050f1ed..19853aaf2 100644 --- a/src/lib/isIBAN.js +++ b/src/lib/isIBAN.js @@ -60,6 +60,7 @@ const ibanRegexThroughCountryCode = { MR: /^(MR[0-9]{2})\d{23}$/, MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/, MU: /^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/, + MZ: /^(MZ[0-9]{2})\d{21}$/, NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/, NO: /^(NO[0-9]{2})\d{11}$/, PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/, diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 903236222..3ec57b2a0 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -91,6 +91,7 @@ const phones = { 'lt-LT': /^(\+370|8)\d{8}$/, 'lv-LV': /^(\+?371)2\d{7}$/, 'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/, + 'mz-MZ': /^(\+?258)?8[234567]\d{7}$/, 'nb-NO': /^(\+?47)?[49]\d{7}$/, 'ne-NP': /^(\+?977)?9[78]\d{8}$/, 'nl-BE': /^(\+?32|0)4?\d{8}$/, diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index ceda6ff02..51a8e70ac 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -43,6 +43,7 @@ const passportRegexByCountryCode = { LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA LY: /^[A-Z0-9]{8}$/, // LIBYA MT: /^\d{7}$/, // MALTA + MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/, // MOZAMBIQUE MY: /^[AHK]\d{8}$/, // MALAYSIA NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS PO: /^[A-Z]{2}\d{7}$/, // POLAND diff --git a/test/validators.js b/test/validators.js index 52146fa82..ce781c9da 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2773,7 +2773,6 @@ describe('Validators', () => { '4017173LV', ], }); - test({ validator: 'isPassportNumber', args: ['LY'], @@ -2799,7 +2798,19 @@ describe('Validators', () => { 'MT01234', ], }); - + test({ + validator: 'isPassportNumber', + args: ['MZ'], + valid: [ + 'AB0808212', + '08AB12123', + ], + invalid: [ + '1AB011241', + '1AB01121', + 'ABAB01121', + ], + }); test({ validator: 'isPassportNumber', args: ['MY'], @@ -4472,6 +4483,7 @@ describe('Validators', () => { 'BR1500000000000010932840814P2', 'LB92000700000000123123456123', 'IR200170000000339545727003', + 'MZ97123412341234123412341', ], invalid: [ 'XX22YYY1234567890123', @@ -5843,6 +5855,50 @@ describe('Validators', () => { '064349089895623459', ], }, + { + locale: 'mz-MZ', + valid: [ + '+258849229754', + '258849229754', + '849229754', + '829229754', + '839229754', + '869229754', + '859229754', + '869229754', + '879229754', + '+258829229754', + '+258839229754', + '+258869229754', + '+258859229754', + '+258869229754', + '+258879229754', + '258829229754', + '258839229754', + '258869229754', + '258859229754', + '258869229754', + '258879229754', + ], + invalid: [ + '+248849229754', + '158849229754', + '249229754', + '819229754', + '899229754', + '889229754', + '89229754', + '8619229754', + '87922975411', + '257829229754', + '+255839229754', + '+2258869229754', + '+1258859229754', + '+2588692297541', + '+2588792519754', + '25882922975411', + ], + }, { locale: 'pt-BR', valid: [ From cf403d097963e22736d54d8cf3aece68f9426299 Mon Sep 17 00:00:00 2001 From: Ezrqn Kemboi Date: Sun, 18 Apr 2021 20:07:59 +0300 Subject: [PATCH 041/113] fix(isMobilePhone): add Sierra Leone phone and fix Sri Lanka phone (#1558) Fixes #1557 --- README.md | 2 +- src/lib/isMobilePhone.js | 3 ++- test/validators.js | 35 +++++++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 965973930..7dbed1295 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 3ec57b2a0..95b568547 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -47,7 +47,7 @@ const phones = { 'en-PH': /^(09|\+639)\d{9}$/, 'en-RW': /^(\+?250|0)?[7]\d{8}$/, 'en-SG': /^(\+65)?[3689]\d{7}$/, - 'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/, + 'en-SL': /^(\+?232|0)\d{8}$/, '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})$/, @@ -103,6 +103,7 @@ const phones = { 'pt-AO': /^(\+244)\d{9}$/, 'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/, 'ru-RU': /^(\+?7|8)?9\d{9}$/, + 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/, '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}$/, 'sq-AL': /^(\+355|0)6[789]\d{6}$/, diff --git a/test/validators.js b/test/validators.js index ce781c9da..31b7f960e 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6592,6 +6592,25 @@ describe('Validators', () => { '+99676338855', ], }, + { + locale: 'si-LK', + valid: [ + '+94766661206', + '94713114340', + '0786642116', + '078 7642116', + '078-7642116', + + ], + invalid: [ + '9912349956789', + '12345', + '1678123456', + '0731234567', + '0749994567', + '0797878674', + ], + }, { locale: 'sr-RS', valid: [ @@ -7622,20 +7641,16 @@ describe('Validators', () => { { locale: 'en-SL', valid: [ - '+94766661206', - '94713114340', - '0786642116', - '078 7642116', - '078-7642116', - + '+23274560591', + '23274560591', + '074560591', ], invalid: [ - '9912349956789', + '0745605912', '12345', - '1678123456', - '0731234567', - '0749994567', + '232745605917', '0797878674', + '23274560591 ', ], }, { From 1fa095914cee4e932582dbab4adb273bd74b2ffb Mon Sep 17 00:00:00 2001 From: Ezrqn Kemboi Date: Sun, 18 Apr 2021 20:11:11 +0300 Subject: [PATCH 042/113] chore: add typeof utility (#1648) --- src/lib/util/typeOf.js | 10 ++++++++++ test/util.js | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/lib/util/typeOf.js create mode 100644 test/util.js diff --git a/src/lib/util/typeOf.js b/src/lib/util/typeOf.js new file mode 100644 index 000000000..f96af511a --- /dev/null +++ b/src/lib/util/typeOf.js @@ -0,0 +1,10 @@ +/** + * Better way to handle type checking + * null, {}, array and date are objects, which confuses + */ +export default function typeOf(input) { + const rawObject = Object.prototype.toString.call(input).toLowerCase(); + const typeOfRegex = /\[object (.*)]/g; + const type = typeOfRegex.exec(rawObject)[1]; + return type; +} diff --git a/test/util.js b/test/util.js new file mode 100644 index 000000000..449cd9ee7 --- /dev/null +++ b/test/util.js @@ -0,0 +1,20 @@ +/** + * All tests that tests any utility. + * Prevent any breaking of functionality + */ +import assert from 'assert'; +import typeOf from '../src/lib/util/typeOf'; + +describe('Util', () => { + it('should validate different typeOf', () => { + assert.strictEqual(typeOf([]), 'array'); + assert.strictEqual(typeOf(null), 'null'); + assert.strictEqual(typeOf({}), 'object'); + assert.strictEqual(typeOf(new Date()), 'date'); + assert.strictEqual(typeOf('ezkemboi'), 'string'); + assert.strictEqual(typeOf(String('kemboi')), 'string'); + assert.strictEqual(typeOf(undefined), 'undefined'); + assert.strictEqual(typeOf(2021), 'number'); + assert.notStrictEqual(typeOf([]), 'object'); + }); +}); From 2a3a1c33607698d69fc788c3b9efddffa6195193 Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Sun, 18 Apr 2021 22:20:08 +0300 Subject: [PATCH 043/113] 13.6.0 --- CHANGELOG.md | 45 ++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- src/index.js | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 865459dd6..4608e74ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,47 @@ -#### ~13.5.0~ 13.5.1 +#### 13.6.0 + +- **New features**: + - [#1495](https://github.com/validatorjs/validator.js/pull/1495) `isLicensePlate` @firlus + +- **Fixes and Enhancements**: + - [#1644](https://github.com/validatorjs/validator.js/pull/1644) `isURL`: Allow URLs to have only a username in the userinfo subcomponent @jbuchmann-coosto + - [#1633](https://github.com/validatorjs/validator.js/pull/1633) `isISIN`: optimization @bmacnaughton + - [#1632](https://github.com/validatorjs/validator.js/pull/1632) `isIP`: improved pattern for IPv4 and IPv6 @ognjenjevremovic + - [#1625](https://github.com/validatorjs/validator.js/pull/1625) fix `[A-z]` regex range on some validators @bmacnaughton + - [#1620](https://github.com/validatorjs/validator.js/pull/1620) fix docs @prahaladbelavadi + - [#1616](https://github.com/validatorjs/validator.js/pull/1616) `isMacAddress`: improve regexes and options @fedeci + - [#1603](https://github.com/validatorjs/validator.js/pull/1603) fix ReDOS vulnerabilities in `isSlug` and `rtrim` @fedeci + - [#1594](https://github.com/validatorjs/validator.js/pull/1594) `isIPRange`: add support for IPv6 @neilime + - [#1577](https://github.com/validatorjs/validator.js/pull/1577) `isEAN`: add support for EAN-14 @varsubham @tux-tn + - [#1566](https://github.com/validatorjs/validator.js/pull/1566) `isStrongPassword`: add `@` as a valid symbol @stingalleman + - [#1548](https://github.com/validatorjs/validator.js/pull/1548) `isBtcAddress`: add base58 @ezkemboi + - [#1546](https://github.com/validatorjs/validator.js/pull/1546) `isFQDN`: numeric domain names @tux-tn + +- **New and Improved locales**: + - `isIdentityCard`, `isPassportNumber`: + - [#1595](https://github.com/validatorjs/validator.js/pull/1595) `IR` @mhf-ir @fedeci + - [#1583](https://github.com/validatorjs/validator.js/pull/1583) `ar-LY` @asghaier76 @tux-tn + - [#1574](https://github.com/validatorjs/validator.js/pull/1574) `MY` @stranger26 @tux-tn + - `isMobilePhone`: + - [#1642](https://github.com/validatorjs/validator.js/pull/1642) `zh-CN` @Akira0705 + - [#1638](https://github.com/validatorjs/validator.js/pull/1638) `lv-LV` @AntonLukichev + - [#1635](https://github.com/validatorjs/validator.js/pull/1635) `en-GH` @ankorGH + - [#1604](https://github.com/validatorjs/validator.js/pull/1604) `mz-MZ` @salmento @tux-tn + - [#1575](https://github.com/validatorjs/validator.js/pull/1575) `vi-VN` @kyled7 + - [#1573](https://github.com/validatorjs/validator.js/pull/1573) `en-SG` @liliwei25 + - [#1554](https://github.com/validatorjs/validator.js/pull/1554) `de-CH`, `fr-CH`, `it-CH` @dinfekted + - [#1541](https://github.com/validatorjs/validator.js/pull/1541) [#1623](https://github.com/validatorjs/validator.js/pull/1623) `es-CO` @ezkemboi @tux-tn + - [#1506](https://github.com/validatorjs/validator.js/pull/1506) `ar-OM` @dev-sna + - [#1505](https://github.com/validatorjs/validator.js/pull/1505) `pt-AO` @AdilsonFuxe + - `isPostalCode`: + - [#1628](https://github.com/validatorjs/validator.js/pull/1628) `KR` @greatSumini + - `isTaxID`: + - [#1613](https://github.com/validatorjs/validator.js/pull/1613) `pt-BR` @mschunke + - [#1529](https://github.com/validatorjs/validator.js/pull/1529) `el-GR` @dspinellis + - `isVAT`: + - [#1536](https://github.com/validatorjs/validator.js/pull/1536) `IT` @fedeci + +#### ~~13.5.0~~ 13.5.1 - **New features**: - `isVAT` [#1463](https://github.com/validatorjs/validator.js/pull/1463) @ CodingNagger diff --git a/package.json b/package.json index 8122a7f64..324f80936 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "validator", "description": "String validation and sanitization", - "version": "13.5.1", + "version": "13.6.0", "sideEffects": false, "homepage": "https://github.com/validatorjs/validator.js", "files": [ diff --git a/src/index.js b/src/index.js index e91c582da..675947481 100644 --- a/src/index.js +++ b/src/index.js @@ -120,7 +120,7 @@ import isStrongPassword from './lib/isStrongPassword'; import isVAT from './lib/isVAT'; -const version = '13.5.1'; +const version = '13.6.0'; const validator = { version, From b986f3ddb6e6feea654c649293565e92e73010cc Mon Sep 17 00:00:00 2001 From: Sarhan Aissi Date: Tue, 20 Apr 2021 10:42:18 +0100 Subject: [PATCH 044/113] fix: ReDOS in isEmail and isHSL (#1651) * chore: bump mocha version to fix npm audit warning * fix(isHSL): update hslComma regex to prevent ReDOS * fix(isEmail): update splitNameAddress regex to prevent ReDOS * chore: rollback mocha version to allow testing on node 8 and 6 * fix(isHSL): remove unnecessary use of let closes #1597 #1598 --- package.json | 2 +- src/lib/isEmail.js | 16 +++++++++------- src/lib/isHSL.js | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 324f80936..72573e375 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "eslint": "^4.19.1", "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "^2.11.0", - "mocha": "^5.1.1", + "mocha": "^6.2.3", "nyc": "^14.1.0", "rimraf": "^3.0.0", "rollup": "^0.43.0", diff --git a/src/lib/isEmail.js b/src/lib/isEmail.js index b570cb254..ecbd398c9 100644 --- a/src/lib/isEmail.js +++ b/src/lib/isEmail.js @@ -16,7 +16,7 @@ const default_email_options = { /* eslint-disable max-len */ /* eslint-disable no-control-regex */ -const splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)<(.+)>$/i; +const splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)$)/g, ''); + // sometimes need to trim the last space to get the display name // because there may be a space between display name and email address // eg. myname diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index b4f446334..05cb43962 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,10 +1,19 @@ import assertString from './util/assertString'; -const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; -const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslComma = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(,(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}(,((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?))?\)$/i; +const hslSpace = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(\s(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s?(\/\s((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s?)?\)$/i; + export default function isHSL(str) { assertString(str); - return hslcomma.test(str) || hslspace.test(str); + + // Strip duplicate spaces before calling the validation regex (See #1598 for more info) + const strippedStr = str.replace(/\s+/g, ' ').replace(/\s?(hsla?\(|\)|,)\s?/ig, '$1'); + + if (strippedStr.indexOf(',') !== -1) { + return hslComma.test(strippedStr); + } + + return hslSpace.test(strippedStr); } From 24b3fd3309d1057dd87af3a568def0db01dbaade Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Tue, 20 Apr 2021 12:51:52 +0300 Subject: [PATCH 045/113] 13.6.1 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4608e74ae..aec8e38fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ -#### 13.6.0 +#### 13.6.1 - **New features**: - [#1495](https://github.com/validatorjs/validator.js/pull/1495) `isLicensePlate` @firlus - **Fixes and Enhancements**: + - [#1651](https://github.com/validatorjs/validator.js/pull/1651) fix ReDOS vulnerabilities in `isHSL` and `isEmail` @tux-tn - [#1644](https://github.com/validatorjs/validator.js/pull/1644) `isURL`: Allow URLs to have only a username in the userinfo subcomponent @jbuchmann-coosto - [#1633](https://github.com/validatorjs/validator.js/pull/1633) `isISIN`: optimization @bmacnaughton - [#1632](https://github.com/validatorjs/validator.js/pull/1632) `isIP`: improved pattern for IPv4 and IPv6 @ognjenjevremovic From d1a9b6d8c5bd7350d6a7303085f0269f6a99aa9b Mon Sep 17 00:00:00 2001 From: Joe MacMahon Date: Wed, 21 Apr 2021 14:18:11 +0000 Subject: [PATCH 046/113] fix(isISO8601): disallow prepended and appended strings to RFC 3339 date-time (#1654) Fixes validatorjs/validator.js#1653 Also adds corresponding test cases to ISO 8601 validator --- src/lib/isRFC3339.js | 2 +- test/validators.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/isRFC3339.js b/src/lib/isRFC3339.js index 5b3eaba85..48b025e0f 100644 --- a/src/lib/isRFC3339.js +++ b/src/lib/isRFC3339.js @@ -19,7 +19,7 @@ const partialTime = new RegExp(`${timeHour.source}:${timeMinute.source}:${timeSe const fullDate = new RegExp(`${dateFullYear.source}-${dateMonth.source}-${dateMDay.source}`); const fullTime = new RegExp(`${partialTime.source}${timeOffset.source}`); -const rfc3339 = new RegExp(`${fullDate.source}[ tT]${fullTime.source}`); +const rfc3339 = new RegExp(`^${fullDate.source}[ tT]${fullTime.source}$`); export default function isRFC3339(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index 31b7f960e..56e581d39 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8925,6 +8925,8 @@ describe('Validators', () => { '2010-02-18T16:23.33.600', '2010-02-18T16,25:23:48,444', '2010-13-1', + 'nonsense2021-01-01T00:00:00Z', + '2021-01-01T00:00:00Znonsense', ]; it('should validate ISO 8601 dates', () => { @@ -9107,6 +9109,8 @@ describe('Validators', () => { '2009-05-00 14:39:22+0600', '2009-00-1 14:39:22Z', '2009-05-19T14:39:22', + 'nonsense2021-01-01T00:00:00Z', + '2021-01-01T00:00:00Znonsense', ], }); }); From 907bb07b8d6be7d159791645960eb5f5017a99b6 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Mon, 24 May 2021 23:20:11 +0545 Subject: [PATCH 047/113] feat: added support for indonesian passport number (#1656) * feat: added indonesia passport * fix: updated readme --- README.md | 2 +- src/lib/isPassportNumber.js | 1 + test/validators.js | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7dbed1295..67496d8b5 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Validator | Description **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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. **isOctal(str)** | check if the string is a valid octal number. -**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'MZ', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. +**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'ID', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'MZ', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'KR', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 51a8e70ac..b283a274a 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -33,6 +33,7 @@ const passportRegexByCountryCode = { HU: /^[A-Z]{2}(\d{6}|\d{7})$/, // HUNGARY IE: /^[A-Z0-9]{2}\d{7}$/, // IRELAND IN: /^[A-Z]{1}-?\d{7}$/, // INDIA + ID: /^[A-C]\d{7}$/, // INDONESIA IR: /^[A-Z]\d{8}$/, // IRAN IS: /^(A)\d{7}$/, // ICELAND IT: /^[A-Z0-9]{2}\d{7}$/, // ITALY diff --git a/test/validators.js b/test/validators.js index 56e581d39..c7119487b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2345,6 +2345,22 @@ describe('Validators', () => { ], }); + + test({ + validator: 'isPassportNumber', + args: ['ID'], + valid: [ + 'C1253473', + 'B5948378', + 'A4859472', + ], + invalid: [ + 'D39481728', + 'A-3847362', + '324132132', + ], + }); + test({ validator: 'isPassportNumber', args: ['AR'], From 2595554f07c4da3ef48ce3f1942a3a2c2def24af Mon Sep 17 00:00:00 2001 From: dror-heller Date: Fri, 16 Jul 2021 09:51:19 +0300 Subject: [PATCH 048/113] feat: Export list of country codes that implement IBAN (#1669) * feat(niceToHave): Export list of country codes that implement IBAN * Update src/index.js Co-authored-by: Federico Ciardi * fix(bug): Export isIBANLocales by its correct alias * fix(test): fix name change in test * fix(standards): change members exported name Co-authored-by: drorh Co-authored-by: Federico Ciardi --- src/index.js | 3 ++- src/lib/isIBAN.js | 2 ++ test/exports.js | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 675947481..59b813c1f 100644 --- a/src/index.js +++ b/src/index.js @@ -48,7 +48,7 @@ import isHSL from './lib/isHSL'; import isISRC from './lib/isISRC'; -import isIBAN from './lib/isIBAN'; +import isIBAN, { locales as ibanLocales } from './lib/isIBAN'; import isBIC from './lib/isBIC'; import isMD5 from './lib/isMD5'; @@ -222,6 +222,7 @@ const validator = { isDate, isLicensePlate, isVAT, + ibanLocales, }; export default validator; diff --git a/src/lib/isIBAN.js b/src/lib/isIBAN.js index 19853aaf2..535a95772 100644 --- a/src/lib/isIBAN.js +++ b/src/lib/isIBAN.js @@ -135,3 +135,5 @@ export default function isIBAN(str) { return hasValidIbanFormat(str) && hasValidIbanChecksum(str); } + +export const locales = Object.keys(ibanRegexThroughCountryCode); diff --git a/test/exports.js b/test/exports.js index 32daa9971..0bff532ab 100644 --- a/test/exports.js +++ b/test/exports.js @@ -5,6 +5,7 @@ import { locales as isAlphaLocales } from '../src/lib/isAlpha'; import { locales as isAlphanumericLocales } from '../src/lib/isAlphanumeric'; import { locales as isMobilePhoneLocales } from '../src/lib/isMobilePhone'; import { locales as isFloatLocales } from '../src/lib/isFloat'; +import { locales as ibanCountryCodes } from '../src/lib/isIBAN'; describe('Exports', () => { it('should export validators', () => { @@ -50,4 +51,9 @@ describe('Exports', () => { assert.ok(isFloatLocales instanceof Array); assert.ok(validator.isFloatLocales instanceof Array); }); + + it('should export a list of country codes that implement IBAN', () => { + assert.ok(ibanCountryCodes instanceof Array); + assert.ok(validator.ibanLocales instanceof Array); + }); }); From b82d4e1b1f9dafcc130ca5dd548324a501741369 Mon Sep 17 00:00:00 2001 From: Laura <53280856+laulujan@users.noreply.github.com> Date: Fri, 16 Jul 2021 01:57:36 -0500 Subject: [PATCH 049/113] feat:(isMobilePhone): add mobile number prefix 162 and 165 to zh-CN locale (#1695) --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 95b568547..6bf6d2234 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -114,7 +114,7 @@ const phones = { 'uk-UA': /^(\+?38|8)?0\d{9}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, 'vi-VN': /^(\+?84|0)((3([2-9]))|(5([2689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, - 'zh-CN': /^((\+|00)86)?1([3456789][0-9]|4[579]|6[67]|7[01235678]|9[012356789])[0-9]{8}$/, + 'zh-CN': /^((\+|00)86)?1([3456789][0-9]|4[579]|6[2567]|7[01235678]|9[012356789])[0-9]{8}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, }; /* eslint-enable max-len */ diff --git a/test/validators.js b/test/validators.js index c7119487b..57f2d2b68 100644 --- a/test/validators.js +++ b/test/validators.js @@ -5987,6 +5987,9 @@ describe('Validators', () => { '16565600001', '+8617269427292', '008617269427292', + '16238234822', + '008616238234822', + '+8616238234822', ], invalid: [ '12345', From c87956ac3834201c9e05f0e93299a370ff2dd2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Fri, 16 Jul 2021 13:49:14 +0200 Subject: [PATCH 050/113] feat(isLicensePlate): Add Czech license plates (#1565) * Add Czech license plates to the RegEx mix * Reorder list * Update README * Add tests * Remove trailing space * Add more tests --- README.md | 2 +- src/lib/isLicensePlate.js | 2 ++ test/validators.js | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 67496d8b5..00434af62 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ Validator | Description **isJWT(str)** | check if the string is valid JWT token. **isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.

`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format. **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. -**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR'']` or `any`). +**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR']` or `any`) **isLocale(str)** | check if the string is a locale **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_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index a28d66da8..d81995bff 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -1,6 +1,8 @@ import assertString from './util/assertString'; const validators = { + 'cs-CZ': str => + /^(([ABCDEFHKIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str), 'de-DE': str => /^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS|TR|TÜ|UM|PZ|TP|UE|UN|UH|MN|KK|VB|V|AE|PL|RC|VG|GW|PW|VR|VK|KB|WA|WT|BE|WM|WE|AP|MO|WW|FB|WZ|WI|WB|JE|WF|WO|W|WÜ|BL|Z|GC)[- ]?[A-Z]{1,2}[- ]?\d{1,4}|(AIC|FDB|ABG|SLN|SAW|KLZ|BUL|ESB|NAB|SUL|WST|ABI|AZE|BTF|KÖT|DKB|FEU|ROT|ALZ|SMÜ|WER|AUR|NOR|DÜW|BRK|HAB|TÖL|WOR|BAD|BAR|BER|BIW|EBS|KEM|MÜB|PEG|BGL|BGD|REI|WIL|BKS|BIR|WAT|BOR|BOH|BOT|BRB|BLK|HHM|NEB|NMB|WSF|LEO|HDL|WMS|WZL|BÜS|CHA|KÖZ|ROD|WÜM|CLP|NEC|COC|ZEL|COE|CUX|DAH|LDS|DEG|DEL|RSL|DLG|DGF|LAN|HEI|MED|DON|KIB|ROK|JÜL|MON|SLE|EBE|EIC|HIG|WBS|BIT|PRÜ|LIB|EMD|WIT|ERH|HÖS|ERZ|ANA|ASZ|MAB|MEK|STL|SZB|FDS|HCH|HOR|WOL|FRG|GRA|WOS|FRI|FFB|GAP|GER|BRL|CLZ|GTH|NOH|HGW|GRZ|LÖB|NOL|WSW|DUD|HMÜ|OHA|KRU|HAL|HAM|HBS|QLB|HVL|NAU|HAS|EBN|GEO|HOH|HDH|ERK|HER|WAN|HEF|ROF|HBN|ALF|HSK|USI|NAI|REH|SAN|KÜN|ÖHR|HOL|WAR|ARN|BRG|GNT|HOG|WOH|KEH|MAI|PAR|RID|ROL|KLE|GEL|KUS|KYF|ART|SDH|LDK|DIL|MAL|VIB|LER|BNA|GHA|GRM|MTL|WUR|LEV|LIF|STE|WEL|LIP|VAI|LUP|HGN|LBZ|LWL|PCH|STB|DAN|MKK|SLÜ|MSP|TBB|MGH|MTK|BIN|MSH|EIL|HET|SGH|BID|MYK|MSE|MST|MÜR|WRN|MEI|GRH|RIE|MZG|MIL|OBB|BED|FLÖ|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str), 'de-LI': str => /^FL[- ]?\d{1,5}[UZ]?$/.test(str), diff --git a/test/validators.js b/test/validators.js index 57f2d2b68..675ac0ea7 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10696,6 +10696,31 @@ describe('Validators', () => { 'AAA 00 AAA', ], }); + test({ + validator: 'isLicensePlate', + args: ['cs-CZ'], + valid: [ + 'ALA4011', + '4A23000', + 'DICTAT0R', + 'VETERAN', + 'AZKVIZ8', + '2A45876', + 'DIC-TAT0R', + ], + invalid: [ + '', + 'invalidlicenseplate', + 'LN5758898', + 'X-|$|-X', + 'AE0F-OP4', + 'GO0MER', + '2AAAAAAAA', + 'FS AB 1234 E', + 'GB999 9999 00', + ], + }); + test({ validator: 'isLicensePlate', args: ['pt-BR'], From 044159d7b80aadef0c4b7aba7a4ea0e72a2eaa50 Mon Sep 17 00:00:00 2001 From: Bryan Brophy Date: Fri, 16 Jul 2021 07:05:17 -0500 Subject: [PATCH 051/113] feat(isBoolean) Add loose option to isBoolean validator (#1676) * Add loose option to isBoolean validator * Move boolean array definitions outside of function --- README.md | 2 +- src/lib/isBoolean.js | 13 +++++++++++-- test/validators.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 00434af62..e5cf0489b 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Validator | Description **isBase64(str [, options])** | check if a string is base64 encoded. options is optional and defaults to `{urlSafe: false}`
when `urlSafe` is true it tests the given base64 encoded string is [url safe](https://base64.guru/standards/base64url) **isBefore(str [, date])** | check if the string is a date that's before the specified date. **isBIC(str)** | check if a string is a BIC (Bank Identification Code) or SWIFT code. -**isBoolean(str)** | check if a string is a boolean. +**isBoolean(str [, options])** | check if a string is a boolean.
`options` is an object which defaults to `{ loose: false }`. If loose is is set to false, the validator will strictly match ['true', 'false', '0', '1']. If loose is set to true, the validator will also match 'yes', 'no', and will match a valid boolean string of any case. (eg: ['true', 'True', 'TRUE']). **isBtcAddress(str)** | check if the string is a valid BTC address. **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. diff --git a/src/lib/isBoolean.js b/src/lib/isBoolean.js index e7cb27dfa..9fddc2b48 100644 --- a/src/lib/isBoolean.js +++ b/src/lib/isBoolean.js @@ -1,6 +1,15 @@ import assertString from './util/assertString'; -export default function isBoolean(str) { +const defaultOptions = { loose: false }; +const strictBooleans = ['true', 'false', '1', '0']; +const looseBooleans = [...strictBooleans, 'yes', 'no']; + +export default function isBoolean(str, options = defaultOptions) { assertString(str); - return (['true', 'false', '1', '0'].indexOf(str) >= 0); + + if (options.loose) { + return looseBooleans.includes(str.toLowerCase()); + } + + return strictBooleans.includes(str); } diff --git a/test/validators.js b/test/validators.js index 675ac0ea7..5ee08e869 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8873,6 +8873,37 @@ describe('Validators', () => { }); }); + it('should validate booleans with option loose set to true', () => { + test({ + validator: 'isBoolean', + args: [ + { loose: true }, + ], + valid: [ + 'true', + 'True', + 'TRUE', + 'false', + 'False', + 'FALSE', + '0', + '1', + 'yes', + 'Yes', + 'YES', + 'no', + 'No', + 'NO', + ], + invalid: [ + '1.0', + '0.0', + 'true ', + ' false', + ], + }); + }); + const validISO8601 = [ '2009-12T12:34', '2009', From 01eeaef8f2b708c2e88a604e1668c77ad6aed990 Mon Sep 17 00:00:00 2001 From: Anna Maria Jansen Date: Fri, 16 Jul 2021 14:09:05 +0200 Subject: [PATCH 052/113] feat(isMobilePhone): change the german prefix from '+490' to '+49' or '0' (#1679) * fix: restrict german numbers * fix: allow 0 prefix Co-authored-by: Anna-Maria Jansen --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 6bf6d2234..b2839d679 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -25,7 +25,7 @@ const phones = { 'ca-AD': /^(\+376)?[346]\d{5}$/, '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|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/, + 'de-DE': /^((\+49|0)[1|3])([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7,9}$/, 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/, 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/, 'de-LU': /^(\+352)?((6\d1)\d{6})$/, diff --git a/test/validators.js b/test/validators.js index 5ee08e869..ef24ea448 100644 --- a/test/validators.js +++ b/test/validators.js @@ -5828,21 +5828,20 @@ describe('Validators', () => { { locale: 'de-DE', valid: [ - '+49015123456789', '+4915123456789', '+4930405044550', '015123456789', - '15123456789', - '15623456789', - '15623456789', - '1601234567', - '16012345678', - '1621234567', - '1631234567', - '1701234567', - '17612345678', - '15345678910', - '15412345678', + '015123456789', + '015623456789', + '015623456789', + '01601234567', + '016012345678', + '01621234567', + '01631234567', + '01701234567', + '017612345678', + '015345678910', + '015412345678', ], invalid: [ '34412345678', @@ -5852,6 +5851,7 @@ describe('Validators', () => { '16412345678', '17012345678', '+4912345678910', + '+49015123456789', ], }, { From cff8a2ebee8770079eb18a99cea97d6b368a4b9d Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Fri, 16 Jul 2021 23:10:16 +0545 Subject: [PATCH 053/113] fix: npm installation error (#1697) fixes #1696 --- build-browser.js | 48 +++++++++++++++++++++++------------------------- package.json | 4 ++-- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/build-browser.js b/build-browser.js index 6101d652a..c863bd399 100644 --- a/build-browser.js +++ b/build-browser.js @@ -1,34 +1,32 @@ /* eslint import/no-extraneous-dependencies: 0 */ -import fs from 'fs'; -import { rollup } from 'rollup'; -import babel from 'rollup-plugin-babel'; -import babelPresetEnv from '@babel/preset-env'; -import pkg from './package.json'; +import fs from "fs"; +import { rollup } from "rollup"; +import babel from "rollup-plugin-babel"; +import babelPresetEnv from "@babel/preset-env"; +import pkg from "./package.json"; rollup({ - entry: 'src/index.js', + entry: "src/index.js", plugins: [ babel({ presets: [[babelPresetEnv, { modules: false }]], babelrc: false, }), ], -}).then(bundle => ( - bundle.write({ - dest: 'validator.js', - format: 'umd', - moduleName: pkg.name, - banner: ( - `/*!\n${ - String(fs.readFileSync('./LICENSE')) - .trim() - .split('\n') - .map(l => ` * ${l}`) - .join('\n') - }\n */` - ), - }) -)).catch((e) => { - process.stderr.write(`${e.message}\n`); - process.exit(1); -}); +}) + .then((bundle) => + bundle.write({ + dest: "validator.js", + format: "umd", + moduleName: pkg.name, + banner: `/*!\n${String(fs.readFileSync("./LICENSE")) + .trim() + .split("\n") + .map((l) => ` * ${l}`) + .join("\n")}\n */`, + }) + ) + .catch((e) => { + process.stderr.write(`${e.message}\n`); + process.exit(1); + }); diff --git a/package.json b/package.json index 72573e375..239215331 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "mocha": "^6.2.3", "nyc": "^14.1.0", "rimraf": "^3.0.0", - "rollup": "^0.43.0", + "rollup": "^0.47.0", "rollup-plugin-babel": "^4.0.1", "uglify-js": "^3.0.19" }, @@ -72,4 +72,4 @@ "node": ">= 0.10" }, "license": "MIT" -} +} \ No newline at end of file From e08e79a066641aa11ded770a8345d7c44be1ff1c Mon Sep 17 00:00:00 2001 From: Luis Rivas Date: Fri, 16 Jul 2021 12:26:54 -0500 Subject: [PATCH 054/113] fix(sMobilePhone): regexp for Vietnamese phone number (#1689) --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index b2839d679..48e167dd3 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -113,7 +113,7 @@ const phones = { 'tr-TR': /^(\+?90|0)?5\d{9}$/, 'uk-UA': /^(\+?38|8)?0\d{9}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, - 'vi-VN': /^(\+?84|0)((3([2-9]))|(5([2689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, + 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, 'zh-CN': /^((\+|00)86)?1([3456789][0-9]|4[579]|6[2567]|7[01235678]|9[012356789])[0-9]{8}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, }; diff --git a/test/validators.js b/test/validators.js index ef24ea448..fbc69515c 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6748,6 +6748,8 @@ describe('Validators', () => { '0892405867', '+84888696413', '0878123456', + '84781234567', + '0553803765', ], invalid: [ '12345', @@ -6759,6 +6761,8 @@ describe('Validators', () => { '+841698765432', '841626543219', '0533803765', + '08712345678', + '+0321234567', ], }, { From d36f79c36b8ed7d49f43dcfa696fbc7c6adfe722 Mon Sep 17 00:00:00 2001 From: Sarhan Aissi Date: Fri, 16 Jul 2021 19:22:56 +0100 Subject: [PATCH 055/113] chore: Increase coverage and make codecov more precise (#1658) * fix(isTaxID): fix typo and remove unnecessary conditions * test: add more cases to handle uncovered branches/conditions * chore: make coverage report for codecov more precise Switch from lcov to cobertura to allow handling branch coverage on PR reports --- .github/workflows/ci.yml | 5 +---- package.json | 3 +-- src/lib/isTaxID.js | 22 ++++++++-------------- test/validators.js | 11 +++++++++-- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efa41e11e..21686d855 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,11 +23,8 @@ jobs: run: npm install - name: Run tests run: npm test - - if: matrix.node-version == 14 - name: Generate coverage file - run: npm run test:ci > coverage.lcov - if: matrix.node-version == 14 name: Send coverage info to Codecov uses: codecov/codecov-action@v1 with: - file: ./coverage.lcov + file: ./coverage/cobertura-coverage.xml diff --git a/package.json b/package.json index 239215331..b02fd04a2 100644 --- a/package.json +++ b/package.json @@ -65,8 +65,7 @@ "build:node": "babel src -d .", "build": "npm run build:browser && npm run build:node && npm run build:es", "pretest": "npm run build && npm run lint", - "test": "nyc mocha --require @babel/register --reporter dot", - "test:ci": "nyc report --reporter=text-lcov" + "test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot" }, "engines": { "node": ">= 0.10" diff --git a/src/lib/isTaxID.js b/src/lib/isTaxID.js index f1ebae6d9..ee66ca326 100644 --- a/src/lib/isTaxID.js +++ b/src/lib/isTaxID.js @@ -860,14 +860,10 @@ function plPlCheck(tin) { */ function ptBrCheck(tin) { - tin = tin.replace(/[^\d]+/g, ''); - if (tin === '') return false; - if (tin.length === 11) { let sum; - let ramainder; + let remainder; sum = 0; - tin = tin.replace(/[^\d]+/g, ''); if ( // Reject known invalid CPFs tin === '11111111111' || @@ -883,21 +879,19 @@ function ptBrCheck(tin) { ) return false; for (let i = 1; i <= 9; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i); - ramainder = (sum * 10) % 11; - if ((ramainder === 10) || (ramainder === 11)) ramainder = 0; - if (ramainder !== parseInt(tin.substring(9, 10), 10)) return false; + remainder = (sum * 10) % 11; + if (remainder === 10) remainder = 0; + if (remainder !== parseInt(tin.substring(9, 10), 10)) return false; sum = 0; for (let i = 1; i <= 10; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (12 - i); - ramainder = (sum * 10) % 11; - if ((ramainder === 10) || (ramainder === 11)) ramainder = 0; - if (ramainder !== parseInt(tin.substring(10, 11), 10)) return false; + remainder = (sum * 10) % 11; + if (remainder === 10) remainder = 0; + if (remainder !== parseInt(tin.substring(10, 11), 10)) return false; return true; } - if (tin.length !== 14) { return false; } - if ( // Reject know invalid CNPJs tin === '00000000000000' || tin === '11111111111111' || @@ -1126,7 +1120,7 @@ const taxIdFormat = { 'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i, 'nl-NL': /^\d{9}$/, 'pl-PL': /^\d{10,11}$/, - 'pt-BR': /^\d{11,14}$/, + 'pt-BR': /(?:^\d{11}$)|(?:^\d{14}$)/, 'pt-PT': /^\d{9}$/, 'ro-RO': /^\d{13}$/, 'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/, diff --git a/test/validators.js b/test/validators.js index fbc69515c..7345ed1fb 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10314,12 +10314,19 @@ describe('Validators', () => { '05423994000172', '11867044000130'], invalid: [ + 'ABCDEFGH', '170.691.440-72', - '01494282042', + '11494282142', + '74405265037', '11111111111', + '48469799384', '94.592.973/0001-82', '28592361000192', - '11111111111111'], + '11111111111111', + '111111111111112', + '61938188550993', + '82168365502729', + ], }); test({ validator: 'isTaxID', From f5f4fcd0c920acd919b8307e1b8e0fcc11ad7112 Mon Sep 17 00:00:00 2001 From: Thanayut T Date: Sat, 17 Jul 2021 01:24:41 +0700 Subject: [PATCH 056/113] feat(isIdentityCard): add TH (Thai) (#1657) --- README.md | 2 +- src/lib/isIdentityCard.js | 10 ++++++++++ test/validators.js | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e5cf0489b..25af675ed 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIBAN(str)** | check if a string is a IBAN (International Bank Account Number). -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.

`options` is an object which can contain the keys `allow_hyphens`. Defaults to first format . If allow_hyphens is set to true, the validator will validate the second format. **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). diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 872ff1920..64616340b 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -117,6 +117,16 @@ const validators = { if (k1 !== f[9] || k2 !== f[10]) return false; return true; }, + TH: (str) => { + if (!str.match(/^[1-8]\d{12}$/)) return false; + + // validate check digit + let sum = 0; + for (let i = 0; i < 12; i++) { + sum += parseInt(str[i], 10) * (13 - i); + } + return str[12] === ((11 - (sum % 11)) % 10).toString(); + }, 'he-IL': (str) => { const DNI = /^\d{9}$/; diff --git a/test/validators.js b/test/validators.js index 7345ed1fb..6bb607282 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4690,6 +4690,24 @@ describe('Validators', () => { '92031470790', ], }, + { + locale: 'TH', + valid: [ + '1101230000001', + '1101230000060', + ], + invalid: [ + 'abc', + '1101230', + '11012300000011', + 'aaaaaaaaaaaaa', + '110123abcd001', + '1101230000007', + '0101123450000', + '0101123450004', + '9101123450008', + ], + }, { locale: 'he-IL', valid: [ From 8c4b3b35c3bd36dc3983aadb045422847154451b Mon Sep 17 00:00:00 2001 From: Federico Ciardi Date: Mon, 19 Jul 2021 08:55:37 +0200 Subject: [PATCH 057/113] chore: update pull_request_template.md (#1699) --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 9ade34019..bf7c05a0e 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -3,7 +3,7 @@ Add a descriptive title textbox above, e.g. feat(validatorName): brief title of what has been done --> -{{ briefly describe what you have done in this PR }} + ## Checklist From 5b04cc5216fa0419233861f824823bf791f1f370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Maria=20Pay=C3=A1=20Castillo?= <30294138+jpaya17@users.noreply.github.com> Date: Mon, 20 Sep 2021 16:28:06 +0200 Subject: [PATCH 058/113] perf(isISO31661Alpha2): use a Set along with .has instead of includes (#1724) fix(isBIC): refactor use of CountryCodes using Set's methods --- src/lib/isBIC.js | 2 +- src/lib/isISO31661Alpha2.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/isBIC.js b/src/lib/isBIC.js index 240bfe18b..b5576b24e 100644 --- a/src/lib/isBIC.js +++ b/src/lib/isBIC.js @@ -9,7 +9,7 @@ export default function isBIC(str) { // toUpperCase() should be removed when a new major version goes out that changes // the regex to [A-Z] (per the spec). - if (CountryCodes.indexOf(str.slice(4, 6).toUpperCase()) < 0) { + if (!CountryCodes.has(str.slice(4, 6).toUpperCase())) { return false; } diff --git a/src/lib/isISO31661Alpha2.js b/src/lib/isISO31661Alpha2.js index e91ae8717..e67bb1e15 100644 --- a/src/lib/isISO31661Alpha2.js +++ b/src/lib/isISO31661Alpha2.js @@ -1,7 +1,7 @@ import assertString from './util/assertString'; // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 -const validISO31661Alpha2CountriesCodes = [ +const validISO31661Alpha2CountriesCodes = new Set([ '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', @@ -27,11 +27,11 @@ const validISO31661Alpha2CountriesCodes = [ 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW', -]; +]); export default function isISO31661Alpha2(str) { assertString(str); - return validISO31661Alpha2CountriesCodes.indexOf(str.toUpperCase()) >= 0; + return validISO31661Alpha2CountriesCodes.has(str.toUpperCase()); } export const CountryCodes = validISO31661Alpha2CountriesCodes; From 7376945b4ce028b65955ae57b8fccbbf3fe58467 Mon Sep 17 00:00:00 2001 From: Sarhan Aissi Date: Tue, 21 Sep 2021 06:08:15 +0100 Subject: [PATCH 059/113] fix(isMagnetURI): update validation regex (#1730) * fix(isMagnetURI): update validation regex - Validate only exact xn topics (btih,sha1,...) - Validate only 32 or 40 hashes - Make tr and dn parameters optional - Allow any other parameter (protocol allow passing non standard parameters) - Use placeholder hashes in tests - Fix ReDOS in old regex - Add new tests * fix(isMagnetURI): prevent matching hashes longer than 40 characters * fix(isMagnetURI): check only string ending after hash or new parameter start --- src/lib/isMagnetURI.js | 2 +- test/validators.js | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/lib/isMagnetURI.js b/src/lib/isMagnetURI.js index 54a3d6654..45b5c8ebf 100644 --- a/src/lib/isMagnetURI.js +++ b/src/lib/isMagnetURI.js @@ -1,6 +1,6 @@ import assertString from './util/assertString'; -const magnetURI = /^magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32,40}&dn=.+&tr=.+$/i; +const magnetURI = /^magnet:\?xt(?:\.1)?=urn:(?:aich|bitprint|btih|ed2k|ed2khash|kzhash|md5|sha1|tree:tiger):[a-z0-9]{32}(?:[a-z0-9]{8})?($|&)/i; export default function isMagnetURI(url) { assertString(url); diff --git a/test/validators.js b/test/validators.js index 6bb607282..f60391a7c 100644 --- a/test/validators.js +++ b/test/validators.js @@ -9297,27 +9297,25 @@ describe('Validators', () => { test({ validator: 'isMagnetURI', valid: [ - 'magnet:?xt=urn:btih:06E2A9683BF4DA92C73A661AC56F0ECC9C63C5B4&dn=helloword2000&tr=udp://helloworld:1337/announce', - 'magnet:?xt=urn:btih:3E30322D5BFC7444B7B1D8DD42404B75D0531DFB&dn=world&tr=udp://world.com:1337', - 'magnet:?xt=urn:btih:4ODKSDJBVMSDSNJVBCBFYFBKNRU875DW8D97DWC6&dn=helloworld&tr=udp://helloworld.com:1337', - 'magnet:?xt=urn:btih:1GSHJVBDVDVJFYEHKFHEFIO8573898434JBFEGHD&dn=foo&tr=udp://foo.com:1337', - 'magnet:?xt=urn:btih:MCJDCYUFHEUD6E2752T7UJNEKHSUGEJFGTFHVBJS&dn=bar&tr=udp://bar.com:1337', - 'magnet:?xt=urn:btih:LAKDHWDHEBFRFVUFJENBYYTEUY837562JH2GEFYH&dn=foobar&tr=udp://foobar.com:1337', - 'magnet:?xt=urn:btih:MKCJBHCBJDCU725TGEB3Y6RE8EJ2U267UNJFGUID&dn=test&tr=udp://test.com:1337', - 'magnet:?xt=urn:btih:UHWY2892JNEJ2GTEYOMDNU67E8ICGICYE92JDUGH&dn=baz&tr=udp://baz.com:1337', - 'magnet:?xt=urn:btih:HS263FG8U3GFIDHWD7829BYFCIXB78XIHG7CWCUG&dn=foz&tr=udp://foz.com:1337', - ], - invalid: [ - '', - ':?xt=urn:btih:06E2A9683BF4DA92C73A661AC56F0ECC9C63C5B4&dn=helloword2000&tr=udp://helloworld:1337/announce', - 'magnett:?xt=urn:btih:3E30322D5BFC7444B7B1D8DD42404B75D0531DFB&dn=world&tr=udp://world.com:1337', - 'xt=urn:btih:4ODKSDJBVMSDSNJVBCBFYFBKNRU875DW8D97DWC6&dn=helloworld&tr=udp://helloworld.com:1337', - 'magneta:?xt=urn:btih:1GSHJVBDVDVJFYEHKFHEFIO8573898434JBFEGHD&dn=foo&tr=udp://foo.com:1337', - 'magnet:?xt=uarn:btih:MCJDCYUFHEUD6E2752T7UJNEKHSUGEJFGTFHVBJS&dn=bar&tr=udp://bar.com:1337', - 'magnet:?xt=urn:btihz&dn=foobar&tr=udp://foobar.com:1337', - 'magnet:?xat=urn:btih:MKCJBHCBJDCU725TGEB3Y6RE8EJ2U267UNJFGUID&dn=test&tr=udp://test.com:1337', - 'magnet::?xt=urn:btih:UHWY2892JNEJ2GTEYOMDNU67E8ICGICYE92JDUGH&dn=baz&tr=udp://baz.com:1337', - 'magnet:?xt:btih:HS263FG8U3GFIDHWD7829BYFCIXB78XIHG7CWCUG&dn=foz&tr=udp://foz.com:1337', + 'magnet:?xt.1=urn:sha1:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456&xt.2=urn:sha1:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456', + 'magnet:?xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234&dn=helloword2000&tr=udp://helloworld:1337/announce', + 'magnet:?xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234&dn=foo', + 'magnet:?xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234&dn=&tr=&nonexisting=hello world', + 'magnet:?xt=urn:md5:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456', + 'magnet:?xt=urn:tree:tiger:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456', + 'magnet:?xt=urn:ed2k:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234', + ], + invalid: [ + ':?xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234', + 'xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234', + 'magneta:?xt=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234', + 'magnet:?xt=uarn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234', + 'magnet:?xt=urn:btihz', + 'magnet::?xt=urn:btih:UHWY2892JNEJ2GTEYOMDNU67E8ICGICYE92JDUGH', + 'magnet:?xt:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'magnet:?xt:urn:nonexisting:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234', + 'magnet:?xt.2=urn:btih:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234', + 'magnet:?xt=urn:ed2k:ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890123456789ABCD', ], }); /* eslint-enable max-len */ From f34112d9109fbe39c8d659b96218e0bfea950533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Maria=20Pay=C3=A1=20Castillo?= <30294138+jpaya17@users.noreply.github.com> Date: Sun, 26 Sep 2021 17:55:48 +0200 Subject: [PATCH 060/113] feat(isISO4217): add currency code validator (#1706) * feat(isISO4217): add currency code validator (#1703) * perf(isISO4217): use a Set along with .has instead of .indexOf * refactor(isISO4217): Enhance tests with lowercase examples --- README.md | 1 + src/index.js | 2 ++ src/lib/isISO4217.js | 38 ++++++++++++++++++++++++++++++++++++++ test/validators.js | 30 ++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 src/lib/isISO4217.js diff --git a/README.md b/README.md index 25af675ed..fc12f70ea 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ Validator | Description **isISO8601(str)** | check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date.
`options` is an object which defaults to `{ strict: false, strictSeparator: false }`. If `strict` is true, date strings with invalid dates like `2009-02-29` will be invalid. If `strictSeparator` is true, date strings with date and time separated by anything other than a T will be invalid. **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. +**isISO4217(str)** | check if the string is a valid [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) officially assigned currency code. **isISRC(str)** | check if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code). **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. **isJSON(str [, options])** | check if the string is valid JSON (note: uses JSON.parse).

`options` is an object which defaults to `{ allow_primitives: false }`. If `allow_primitives` is true, the primitives 'true', 'false' and 'null' are accepted as valid JSON values. diff --git a/src/index.js b/src/index.js index 59b813c1f..a0e8aa63c 100644 --- a/src/index.js +++ b/src/index.js @@ -90,6 +90,7 @@ import isISO8601 from './lib/isISO8601'; import isRFC3339 from './lib/isRFC3339'; import isISO31661Alpha2 from './lib/isISO31661Alpha2'; import isISO31661Alpha3 from './lib/isISO31661Alpha3'; +import isISO4217 from './lib/isISO4217'; import isBase32 from './lib/isBase32'; import isBase58 from './lib/isBase58'; @@ -198,6 +199,7 @@ const validator = { isRFC3339, isISO31661Alpha2, isISO31661Alpha3, + isISO4217, isBase32, isBase58, isBase64, diff --git a/src/lib/isISO4217.js b/src/lib/isISO4217.js new file mode 100644 index 000000000..0738614c9 --- /dev/null +++ b/src/lib/isISO4217.js @@ -0,0 +1,38 @@ +import assertString from './util/assertString'; + +// from https://en.wikipedia.org/wiki/ISO_4217 +const validISO4217CurrencyCodes = new Set([ + 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', + 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', + 'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', + 'DJF', 'DKK', 'DOP', 'DZD', + 'EGP', 'ERN', 'ETB', 'EUR', + 'FJD', 'FKP', + 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', + 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', + 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', + 'JMD', 'JOD', 'JPY', + 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', + 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', + 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MXV', 'MYR', 'MZN', + 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', + 'OMR', + 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', + 'QAR', + 'RON', 'RSD', 'RUB', 'RWF', + 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', + 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', + 'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS', + 'VES', 'VND', 'VUV', + 'WST', + 'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX', + 'YER', + 'ZAR', 'ZMW', 'ZWL', +]); + +export default function isISO4217(str) { + assertString(str); + return validISO4217CurrencyCodes.has(str.toUpperCase()); +} + +export const CurrencyCodes = validISO4217CurrencyCodes; diff --git a/test/validators.js b/test/validators.js index f60391a7c..0e73d1542 100644 --- a/test/validators.js +++ b/test/validators.js @@ -9242,6 +9242,36 @@ describe('Validators', () => { }); }); + it('should validate ISO 4217 corrency codes', () => { + // from https://en.wikipedia.org/wiki/ISO_4217 + test({ + validator: 'isISO4217', + valid: [ + 'AED', + 'aed', + 'AUD', + 'CUC', + 'EUR', + 'GBP', + 'LYD', + 'MYR', + 'SGD', + 'USD', + ], + invalid: [ + '', + '$', + 'US', + 'us', + 'AAA', + 'aaa', + 'RWA', + 'EURO', + 'euro', + ], + }); + }); + it('should validate whitelisted characters', () => { test({ validator: 'isWhitelisted', From 5b649c66919952aa6655a87c4c7d8cc7e34a698f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Maria=20Pay=C3=A1=20Castillo?= <30294138+jpaya17@users.noreply.github.com> Date: Sun, 26 Sep 2021 17:56:30 +0200 Subject: [PATCH 061/113] perf(isISO31661Alpha3): use a Set along with .has instead of includes (#1708) --- src/lib/isISO31661Alpha3.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/isISO31661Alpha3.js b/src/lib/isISO31661Alpha3.js index 00c3dfb14..34e552cdd 100644 --- a/src/lib/isISO31661Alpha3.js +++ b/src/lib/isISO31661Alpha3.js @@ -1,8 +1,7 @@ import assertString from './util/assertString'; -import includes from './util/includes'; // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 -const validISO31661Alpha3CountriesCodes = [ +const validISO31661Alpha3CountriesCodes = new Set([ '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', @@ -19,9 +18,9 @@ const validISO31661Alpha3CountriesCodes = [ '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', -]; +]); export default function isISO31661Alpha3(str) { assertString(str); - return includes(validISO31661Alpha3CountriesCodes, str.toUpperCase()); + return validISO31661Alpha3CountriesCodes.has(str.toUpperCase()); } From b0d49bd8aa91e7be58693cf99731d1b910614bd4 Mon Sep 17 00:00:00 2001 From: Aleksander Panteleev Date: Sun, 26 Sep 2021 19:05:49 +0300 Subject: [PATCH 062/113] fix(isDate): fix isdate format validation (#1711) --- src/lib/isDate.js | 2 +- test/validators.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib/isDate.js b/src/lib/isDate.js index 110c2193a..8b7862e8b 100644 --- a/src/lib/isDate.js +++ b/src/lib/isDate.js @@ -7,7 +7,7 @@ const default_date_options = { }; function isValidFormat(format) { - return /(^(y{4}|y{2})[\/-](m{1,2})[\/-](d{1,2})$)|(^(m{1,2})[\/-](d{1,2})[\/-]((y{4}|y{2})$))|(^(d{1,2})[\/-](m{1,2})[\/-]((y{4}|y{2})$))/gi.test(format); + return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format); } function zip(date, format) { diff --git a/test/validators.js b/test/validators.js index 0e73d1542..359ec2c78 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10702,6 +10702,25 @@ describe('Validators', () => { '2020/03-15', ], }); + test({ + validator: 'isDate', + args: [{ format: 'MM.DD.YYYY', delimiters: ['.'], strictMode: true }], + valid: [ + '01.15.2020', + '02.15.2014', + '03.15.2014', + '02.29.2020', + ], + invalid: [ + '2014-02-15', + '2020-02-29', + '15-07/2002', + new Date(), + new Date([2014, 2, 15]), + new Date('2014-03-15'), + '29.02.2020', + ], + }); }); it('should be valid license plate', () => { test({ From 69881b6992f014e314719fad4f60a42d10e2a080 Mon Sep 17 00:00:00 2001 From: Anirudh Giri <35490486+anirudhgiri@users.noreply.github.com> Date: Sun, 26 Sep 2021 21:37:10 +0530 Subject: [PATCH 063/113] feat(isPassportNumber): fix regex for CN (#1714) * fix: (isPassportNumber) fix regex for CN * feat(isPassportNumber): fix regex for CN (validatorjs#1686) --- src/lib/isPassportNumber.js | 2 +- test/validators.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index b283a274a..76284b12f 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -17,7 +17,7 @@ const passportRegexByCountryCode = { BY: /^[A-Z]{2}\d{7}$/, // BELARUS CA: /^[A-Z]{2}\d{6}$/, // CANADA CH: /^[A-Z]\d{7}$/, // SWITZERLAND - CN: /^[GE]\d{8}$/, // CHINA [G=Ordinary, E=Electronic] followed by 8-digits + CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/, // CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits CY: /^[A-Z](\d{6}|\d{8})$/, // CYPRUS CZ: /^\d{8}$/, // CZECH REPUBLIC DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/, // GERMANY diff --git a/test/validators.js b/test/validators.js index 359ec2c78..44ce4ce7c 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2475,9 +2475,15 @@ describe('Validators', () => { valid: [ 'G25352389', 'E00160027', + 'EA1234567', ], invalid: [ 'K0123456', + 'E-1234567', + 'G.1234567', + 'GA1234567', + 'EI1234567', + 'GO1234567', ], }); From e84623b06c7601845d60fdb7af8b4434a40bbc79 Mon Sep 17 00:00:00 2001 From: Shreyas Sai Date: Sun, 26 Sep 2021 21:38:31 +0530 Subject: [PATCH 064/113] feat(isCreditCard): Fixed regex for Union Pay Credit cards with 81 range (#1715) * Fixes #1680 * Added Tests --- src/lib/isCreditCard.js | 2 +- test/validators.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/isCreditCard.js b/src/lib/isCreditCard.js index 2b6f2b217..b11c4cc90 100644 --- a/src/lib/isCreditCard.js +++ b/src/lib/isCreditCard.js @@ -1,7 +1,7 @@ import assertString from './util/assertString'; /* eslint-disable max-len */ -const creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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})$/; +const creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|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,15}|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}|^(81[0-9]{14,17}))$/; /* eslint-enable max-len */ export default function isCreditCard(str) { diff --git a/test/validators.js b/test/validators.js index 44ce4ce7c..6270d6464 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4575,6 +4575,8 @@ describe('Validators', () => { '2718760626256570', '6765780016990268', '4716989580001715211', + '8171999927660000', + '8171999900000000021', ], invalid: [ 'foo', From b069167f7a7537dc2e9eaee500f031465b385a57 Mon Sep 17 00:00:00 2001 From: Mihir Kumar Date: Sun, 26 Sep 2021 21:40:22 +0530 Subject: [PATCH 065/113] feat(isAlpha, isAlphanumeric): Adds Hindi (hi-IN) language support addition to isAlpha & isAlphanumeric (#1716) * feat: :sparkles: Hindi language support addition This commit introduces Indian Hindi language support (hi-IN) * * test: :white_check_mark: test case for alphanumeric added --- README.md | 4 ++-- src/lib/alpha.js | 4 +++- test/validators.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fc12f70ea..71b469c24 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ Validator | Description **contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false}`.
`ignoreCase` specified whether the case of the substring be same or not. **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, options])** | 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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. -**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlpha(str [, locale, options])** | 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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', 'hi-IN', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', 'hi-IN', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. **isAscii(str)** | check if the string contains ASCII chars only. **isBase32(str)** | check if a string is base32 encoded. **isBase58(str)** | check if a string is base58 encoded. diff --git a/src/lib/alpha.js b/src/lib/alpha.js index c898cacfe..27d3fbc6c 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -30,6 +30,7 @@ export const alpha = { ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, he: /^[א-ת]+$/, fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i, + 'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i, }; export const alphanumeric = { @@ -63,6 +64,7 @@ export const alphanumeric = { ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, he: /^[0-9א-ת]+$/, fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i, + 'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i, }; export const decimal = { @@ -107,7 +109,7 @@ for (let locale, i = 0; i < farsiLocales.length; i++) { export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY']; export const commaDecimal = [ 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR', - 'id-ID', 'it-IT', 'ku-IQ', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', + 'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN', ]; diff --git a/test/validators.js b/test/validators.js index 6270d6464..832f9cde0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1627,6 +1627,25 @@ describe('Validators', () => { }); }); + it('should validate Hindi alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['hi-IN'], + valid: [ + 'अतअपनाअपनीअपनेअभीअंदरआदिआपइत्यादिइनइनकाइन्हींइन्हेंइन्होंइसइसकाइसकीइसकेइसमेंइसीइसेउनउनकाउनकीउनकेउनकोउन्हींउन्हेंउन्होंउसउसकेउसीउसेएकएवंएसऐसेऔरकईकरकरताकरतेकरनाकरनेकरेंकहतेकहाकाकाफ़ीकिकितनाकिन्हेंकिन्होंकियाकिरकिसकिसीकिसेकीकुछकुलकेकोकोईकौनकौनसागयाघरजबजहाँजाजितनाजिनजिन्हेंजिन्होंजिसजिसेजीधरजैसाजैसेजोतकतबतरहतिनतिन्हेंतिन्होंतिसतिसेतोथाथीथेदबारादियादुसरादूसरेदोद्वाराननकेनहींनानिहायतनीचेनेपरपहलेपूरापेफिरबनीबहीबहुतबादबालाबिलकुलभीभीतरमगरमानोमेमेंयदियहयहाँयहीयायिहयेरखेंरहारहेऱ्वासालिएलियेलेकिनववग़ैरहवर्गवहवहाँवहींवालेवुहवेवोसकतासकतेसबसेसभीसाथसाबुतसाभसारासेसोसंगहीहुआहुईहुएहैहैंहोहोताहोतीहोतेहोनाहोने', + 'इन्हें', + ], + invalid: [ + 'अत०२३४५६७८९', + 'अत 12', + ' अत ', + 'abc1', + 'abc', + '', + ], + }); + }); + it('should validate persian alpha strings', () => { test({ validator: 'isAlpha', @@ -1985,6 +2004,26 @@ describe('Validators', () => { }); }); + it('should validate Hindi alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['hi-IN'], + valid: [ + 'अतअपनाअपनीअपनेअभीअंदरआदिआपइत्यादिइनइनकाइन्हींइन्हेंइन्होंइसइसकाइसकीइसकेइसमेंइसीइसेउनउनकाउनकीउनकेउनकोउन्हींउन्हेंउन्होंउसउसकेउसीउसेएकएवंएसऐसेऔरकईकरकरताकरतेकरनाकरनेकरेंकहतेकहाकाकाफ़ीकिकितनाकिन्हेंकिन्होंकियाकिरकिसकिसीकिसेकीकुछकुलकेकोकोईकौनकौनसागयाघरजबजहाँजाजितनाजिनजिन्हेंजिन्होंजिसजिसेजीधरजैसाजैसेजोतकतबतरहतिनतिन्हेंतिन्होंतिसतिसेतोथाथीथेदबारादियादुसरादूसरेदोद्वाराननकेनहींनानिहायतनीचेनेपरपहलेपूरापेफिरबनीबहीबहुतबादबालाबिलकुलभीभीतरमगरमानोमेमेंयदियहयहाँयहीयायिहयेरखेंरहारहेऱ्वासालिएलियेलेकिनववग़ैरहवर्गवहवहाँवहींवालेवुहवेवोसकतासकतेसबसेसभीसाथसाबुतसाभसारासेसोसंगहीहुआहुईहुएहैहैंहोहोताहोतीहोतेहोनाहोने०२३४५६७८९', + 'इन्हें४५६७८९', + ], + invalid: [ + 'अत ०२३४५६७८९', + ' ३४५६७८९', + '12 ', + ' अत ', + 'abc1', + 'abc', + '', + ], + }); + }); + it('should validate farsi alphanumeric strings', () => { test({ validator: 'isAlphanumeric', From a3497bddb7e15a5295f4c23fae007a2b70705907 Mon Sep 17 00:00:00 2001 From: Dustin Date: Sun, 26 Sep 2021 18:12:09 +0200 Subject: [PATCH 066/113] fix(isEmail): replace all dots in gmail length validation (#1718) --- src/lib/isEmail.js | 2 +- test/validators.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/isEmail.js b/src/lib/isEmail.js index ecbd398c9..8f1dcd98a 100644 --- a/src/lib/isEmail.js +++ b/src/lib/isEmail.js @@ -110,7 +110,7 @@ export default function isEmail(str, options) { const username = user.split('+')[0]; // Dots are not included in gmail length restriction - if (!isByteLength(username.replace('.', ''), { min: 6, max: 30 })) { + if (!isByteLength(username.replace(/\./g, ''), { min: 6, max: 30 })) { return false; } diff --git a/test/validators.js b/test/validators.js index 832f9cde0..5c0f6af1a 100644 --- a/test/validators.js +++ b/test/validators.js @@ -70,7 +70,7 @@ describe('Validators', () => { 'hans@m端ller.com', 'test|123@m端ller.com', 'test123+ext@gmail.com', - 'some.name.midd.leNa.me+extension@GoogleMail.com', + 'some.name.midd.leNa.me.and.locality+extension@GoogleMail.com', '"foobar"@example.com', '" foo m端ller "@example.com', '"foo\\@bar"@example.com', From 326cfb9c1e74debc0fdfa032893b1c8560c83ae9 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Mon, 27 Sep 2021 05:14:08 +1300 Subject: [PATCH 067/113] feat(isURL): add `allow_fragments` and `allow_query_components` (#1721) * feat(isURL): add `allow_fragments` option * feat(isURL): add `allow_query_components` option --- README.md | 2 +- src/lib/isURL.js | 10 ++++++++++ test/validators.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 71b469c24..477cf358b 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ Validator | Description **isSlug** | Check if the string is of type slug. `Options` allow a single hyphen between string. e.g. [`cn-cn`, `cn-c-c`] **isStrongPassword(str [, options])** | Check if a password is strong or not. Allows for custom requirements or scoring rules. If `returnScore` is true, then the function returns an integer score for the password rather than a boolean.
Default options:
`{ minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1, returnScore: false, pointsPerUnique: 1, pointsPerRepeat: 0.5, pointsForContainingLower: 10, pointsForContainingUpper: 10, pointsForContainingNumber: 10, pointsForContainingSymbol: 10 }` **isTaxID(str, locale)** | Check if the given value is a valid Tax Identification Number. Default locale is `en-US`.

More info about exact TIN support can be found in `src/lib/isTaxID.js`

Supported locales: `[ 'bg-BG', 'cs-CZ', 'de-AT', 'de-DE', 'dk-DK', 'el-CY', 'el-GR', 'en-GB', 'en-IE', 'en-US', 'es-ES', 'et-EE', 'fi-FI', 'fr-BE', 'fr-FR', 'fr-LU', 'hr-HR', 'hu-HU', 'it-IT', 'lb-LU', 'lt-LT', 'lv-LV' 'mt-MT', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE' ]` -**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_port: false, 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, validate_length: true }`.

require_protocol - if set as true isURL will return false if protocol is not present in the URL.
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
protocols - valid protocols can be modified with this option.
require_host - if set as false isURL will not check if host is present in the URL.
require_port - if set as true isURL will check if port is present in the URL.
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.
validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). +**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_port: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, allow_fragments: true, allow_query_components: true, disallow_auth: false, validate_length: true }`.

require_protocol - if set as true isURL will return false if protocol is not present in the URL.
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
protocols - valid protocols can be modified with this option.
require_host - if set as false isURL will not check if host is present in the URL.
require_port - if set as true isURL will check if port is present in the URL.
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.
allow_fragments - if set as false isURL will return false if fragments are present.
allow_query_components - if set as false isURL will return false if query components are present.
validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). **isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). **isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. **isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

Available country codes: `[ 'GB', 'IT' ]`. diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 4306e5deb..254297377 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -28,6 +28,8 @@ const default_url_options = { allow_underscores: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, + allow_fragments: true, + allow_query_components: true, validate_length: true, }; @@ -61,6 +63,14 @@ export default function isURL(url, options) { return false; } + if (!options.allow_fragments && url.includes('#')) { + return false; + } + + if (!options.allow_query_components && (url.includes('?') || url.includes('&'))) { + return false; + } + let protocol, auth, host, hostname, port, port_str, split, ipv6; split = url.split('#'); diff --git a/test/validators.js b/test/validators.js index 5c0f6af1a..50e50d238 100644 --- a/test/validators.js +++ b/test/validators.js @@ -541,6 +541,42 @@ describe('Validators', () => { }); }); + it('should not validate URLs with fragments when allow fragments is false', () => { + test({ + validator: 'isURL', + args: [{ + allow_fragments: false, + }], + valid: [ + 'http://foobar.com', + 'foobar.com', + ], + invalid: [ + 'http://foobar.com#part', + 'foobar.com#part', + ], + }); + }); + + it('should not validate URLs with query components when allow query components is false', () => { + test({ + validator: 'isURL', + args: [{ + allow_query_components: false, + }], + valid: [ + 'http://foobar.com', + 'foobar.com', + ], + invalid: [ + 'http://foobar.com?foo=bar', + 'http://foobar.com?foo=bar&bar=foo', + 'foobar.com?foo=bar', + 'foobar.com?foo=bar&bar=foo', + ], + }); + }); + it('should not validate protocol relative URLs when require protocol is true', () => { test({ validator: 'isURL', From c899b311319ce9e2f725d4601ef9019e077afbec Mon Sep 17 00:00:00 2001 From: islasjuanp Date: Sun, 26 Sep 2021 13:15:29 -0300 Subject: [PATCH 068/113] feat(isMobilePhone): add validation for Venezuela phone numbers (#1720) (#1734) --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 477cf358b..cb278ff16 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 48e167dd3..aabd37512 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -68,6 +68,7 @@ const phones = { 'es-PA': /^(\+?507)\d{7,8}$/, 'es-PY': /^(\+?595|0)9[9876]\d{7}$/, 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/, + 'es-VE': /^(\+?58)?(2|4)\d{9}$/, '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$/, diff --git a/test/validators.js b/test/validators.js index 50e50d238..13e066741 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7139,6 +7139,19 @@ describe('Validators', () => { '099 999 999', ], }, + { + locale: 'es-VE', + valid: [ + '+582125457765', + '+582125458053', + '+584125458053', + ], + invalid: [ + '+585129934395', + '+58212993439', + '', + ], + }, { locale: 'et-EE', valid: [ From 05e382b5ee315890fd1c61602889fb2486a77800 Mon Sep 17 00:00:00 2001 From: Sachin Raja Date: Sat, 2 Oct 2021 12:50:10 -0700 Subject: [PATCH 069/113] refactor: run scripts in parallel for build and clean (#1747) * refactor: run scripts in parallel for build and clean * use globs --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b02fd04a2..a912c032a 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "^2.11.0", "mocha": "^6.2.3", + "npm-run-all": "^4.1.5", "nyc": "^14.1.0", "rimraf": "^3.0.0", "rollup": "^0.47.0", @@ -58,12 +59,12 @@ "clean:node": "rimraf index.js lib", "clean:es": "rimraf es", "clean:browser": "rimraf validator*.js", - "clean": "npm run clean:node && npm run clean:browser && npm run clean:es", + "clean": "run-p clean:*", "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", "build:browser": "node --require @babel/register build-browser && npm run minify", "build:es": "babel src -d es --env-name=es", "build:node": "babel src -d .", - "build": "npm run build:browser && npm run build:node && npm run build:es", + "build": "run-p build:*", "pretest": "npm run build && npm run lint", "test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot" }, @@ -71,4 +72,4 @@ "node": ">= 0.10" }, "license": "MIT" -} \ No newline at end of file +} From 04b73add026ad043bafae6392fd23f9999992447 Mon Sep 17 00:00:00 2001 From: Federico Ciardi Date: Sat, 2 Oct 2021 21:51:58 +0200 Subject: [PATCH 070/113] feat(isEmail): add `host_blacklist` option (#1641) * feat(isEmail): add `domain_denylist` option * Fix tests * Update option name --- README.md | 2 +- src/lib/isEmail.js | 9 +++++++-- test/validators.js | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb278ff16..1baaf0717 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Validator | Description **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', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa', 'fa-AF', 'fa-IR', 'fr-FR', 'fr-CA', 'hu-HU', 'id-ID', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pl-Pl', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN']`.
**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. **isEAN(str)** | check if the string is an EAN (European Article Number). -**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, blacklisted_chars: '' }`. 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 `ignore_max_length` is set to true, the validator will not check for the standard max length of an email. 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. If `blacklisted_chars` receives a string, then the validator will reject emails that include any of the characters in the string, in the name part. +**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, blacklisted_chars: '', host_blacklist: [] }`. 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 `ignore_max_length` is set to true, the validator will not check for the standard max length of an email. 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. If `blacklisted_chars` receives a string, then the validator will reject emails that include any of the characters in the string, in the name part. If `host_blacklist` is set to an array of strings and the part of the email after the `@` symbol matches one of the strings defined in it, the validation fails. **isEmpty(str [, options])** | check if the string has a length of zero.

`options` is an object which defaults to `{ ignore_whitespace:false }`. **isEthereumAddress(str)** | check if the string is an [Ethereum](https://ethereum.org/) address using basic regex. Does not validate address checksums. **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-CA', '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`. diff --git a/src/lib/isEmail.js b/src/lib/isEmail.js index 8f1dcd98a..f24f2dad2 100644 --- a/src/lib/isEmail.js +++ b/src/lib/isEmail.js @@ -12,6 +12,7 @@ const default_email_options = { require_tld: true, blacklisted_chars: '', ignore_max_length: false, + host_blacklist: [], }; /* eslint-disable max-len */ @@ -92,10 +93,14 @@ export default function isEmail(str, options) { const parts = str.split('@'); const domain = parts.pop(); - let user = parts.join('@'); - const lower_domain = domain.toLowerCase(); + if (options.host_blacklist.includes(lower_domain)) { + return false; + } + + let user = parts.join('@'); + if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) { /* Previously we removed dots for gmail addresses before validating. diff --git a/test/validators.js b/test/validators.js index 13e066741..70b3b71fe 100644 --- a/test/validators.js +++ b/test/validators.js @@ -296,7 +296,7 @@ describe('Validators', () => { }); }); - it('should not validate email addresses with blacklisted chars in the name', () => { + it('should not validate email addresses with blacklisted chars in the name', () => { test({ validator: 'isEmail', args: [{ blacklisted_chars: 'abc' }], @@ -330,6 +330,20 @@ describe('Validators', () => { }); }); + it('should not validate email addresses with denylisted domains', () => { + test({ + validator: 'isEmail', + args: [{ host_blacklist: ['gmail.com', 'foo.bar.com'] }], + valid: [ + 'email@foo.gmail.com', + ], + invalid: [ + 'foo+bar@gmail.com', + 'email@foo.bar.com', + ], + }); + }); + it('should validate URLs', () => { test({ validator: 'isURL', From f2a1587c56d8f450ec45006ecbcd134a7810f23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20W=C3=B3jcik?= Date: Sat, 2 Oct 2021 21:54:01 +0200 Subject: [PATCH 071/113] feat(isIdentityCard): Add PL locale (#1745) * Add validation for PESEL * Move PESEL validation to isIdentityCard * Fix consistent-return * Fix trailing-space * Attempt to improve code coverage * Handle else in control sum check * Remove unnecessary return Co-authored-by: Federico Ciardi * Fix linter error * Add missing tests * Add missing test * Replace Array.forEach with Array. reduce Co-authored-by: Sarhan Aissi * Use reduce instead forEach * Simplify reduce function Co-authored-by: Federico Ciardi Co-authored-by: Sarhan Aissi --- README.md | 2 +- src/lib/isIdentityCard.js | 33 +++++++++++++++++++++++++++++++++ test/validators.js | 25 +++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1baaf0717..1ff1e00dc 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIBAN(str)** | check if a string is a IBAN (International Bank Account Number). -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['PL', 'ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.

`options` is an object which can contain the keys `allow_hyphens`. Defaults to first format . If allow_hyphens is set to true, the validator will validate the second format. **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). diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 64616340b..8ea15e262 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -1,6 +1,39 @@ import assertString from './util/assertString'; +import isInt from './isInt'; const validators = { + PL: (str) => { + assertString(str); + + const weightOfDigits = { + 1: 1, + 2: 3, + 3: 7, + 4: 9, + 5: 1, + 6: 3, + 7: 7, + 8: 9, + 9: 1, + 10: 3, + 11: 0, + }; + + if (str != null && str.length === 11 && isInt(str, { allow_leading_zeroes: true })) { + const digits = str.split('').slice(0, -1); + const sum = digits.reduce((acc, digit, index) => + acc + (Number(digit) * weightOfDigits[index + 1]), 0); + + const modulo = sum % 10; + const lastDigit = Number(str.charAt(str.length - 1)); + + if ((modulo === 0 && lastDigit === 0) || lastDigit === 10 - modulo) { + return true; + } + } + + return false; + }, ES: (str) => { assertString(str); diff --git a/test/validators.js b/test/validators.js index 70b3b71fe..6bea81c60 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4686,6 +4686,31 @@ describe('Validators', () => { it('should validate identity cards', () => { const fixtures = [ + { + locale: 'PL', + valid: [ + '99012229019', + '09210215408', + '20313034701', + '86051575214', + '77334586883', + '54007481320', + '06566860643', + '77552478861', + ], + invalid: [ + 'aa', + '5', + '195', + '', + ' ', + '12345678901', + '99212229019', + '09210215402', + '20313534701', + '86241579214', + ], + }, { locale: 'ES', valid: [ From 4ec30b773be5dc9a7d42bb0cfd2c9c35d6e4874a Mon Sep 17 00:00:00 2001 From: Divik Shrivastava Date: Sun, 3 Oct 2021 01:25:36 +0530 Subject: [PATCH 072/113] fix(isMobilePhone.js): regex for Belgium locale (#1746) * Updating regex of Belgium and the valid and invalid phone numbers in validators.js * Fixing accidental deletion of closing braces * Fixing the test numbers for fr-BE (french Belgium) too in validators.js since phone number rules will be same for that too Co-authored-by: Divik Shrivastava --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index aabd37512..8b56b769f 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -95,7 +95,7 @@ const phones = { 'mz-MZ': /^(\+?258)?8[234567]\d{7}$/, 'nb-NO': /^(\+?47)?[49]\d{7}$/, 'ne-NP': /^(\+?977)?9[78]\d{8}$/, - 'nl-BE': /^(\+?32|0)4?\d{8}$/, + 'nl-BE': /^(\+?32|0)4\d{8}$/, 'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/, 'nn-NO': /^(\+?47)?[49]\d{7}$/, 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/, diff --git a/test/validators.js b/test/validators.js index 6bea81c60..91794d521 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7428,9 +7428,9 @@ describe('Validators', () => { '0470123456', '+32470123456', '32470123456', - '021234567', - '+3221234567', - '3221234567', + '0421234567', + '+32421234567', + '32421234567', ], invalid: [ '12345', @@ -7442,6 +7442,9 @@ describe('Validators', () => { '0212345678', '+320212345678', '320212345678', + '021234567', + '+3221234567', + '3221234567', ], }, { @@ -7450,9 +7453,9 @@ describe('Validators', () => { '0470123456', '+32470123456', '32470123456', - '021234567', - '+3221234567', - '3221234567', + '0421234567', + '+32421234567', + '32421234567', ], invalid: [ '12345', @@ -7464,6 +7467,9 @@ describe('Validators', () => { '0212345678', '+320212345678', '320212345678', + '021234567', + '+3221234567', + '3221234567', ], }, { From 13651ea2095c0966576fd7bf44505fb5501681de Mon Sep 17 00:00:00 2001 From: Deepanshu Vangani Date: Tue, 5 Oct 2021 10:47:33 +0530 Subject: [PATCH 073/113] feat(isUrl): higher priority to whitelist (#1748) * isUrl higher priority to whitelist * remove extra line at end of package.json --- src/lib/isURL.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 254297377..7f6e0ba5f 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -145,15 +145,15 @@ export default function isURL(url, options) { return false; } + if (options.host_whitelist) { + return checkHost(host, options.host_whitelist); + } if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) { return false; } host = host || ipv6; - if (options.host_whitelist && !checkHost(host, options.host_whitelist)) { - return false; - } if (options.host_blacklist && checkHost(host, options.host_blacklist)) { return false; } From 622184e669162453e155499417e1a922f548e810 Mon Sep 17 00:00:00 2001 From: Andrea Fassina Date: Sat, 30 Oct 2021 07:56:32 +0200 Subject: [PATCH 074/113] feat(isFQDN): add `allow_wildcard` option (#1647) Co-authored-by: Andrea Fassina --- README.md | 2 +- src/lib/isFQDN.js | 7 +++++++ test/validators.js | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ff1e00dc..f6e8f7117 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Validator | Description **isEmpty(str [, options])** | check if the string has a length of zero.

`options` is an object which defaults to `{ ignore_whitespace:false }`. **isEthereumAddress(str)** | check if the string is an [Ethereum](https://ethereum.org/) address using basic regex. Does not validate address checksums. **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-CA', '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`. -**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 , allow_numeric_tld: 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, allow_numeric_tld: false, allow_wildcard: false }`. If `allow_wildcard` is set to true, the validator will allow domain starting with `*.` (e.g. `*.example.com` or `*.shop.example.com`). **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']` diff --git a/src/lib/isFQDN.js b/src/lib/isFQDN.js index 3dff7d2fd..b82b08941 100644 --- a/src/lib/isFQDN.js +++ b/src/lib/isFQDN.js @@ -6,6 +6,7 @@ const default_fqdn_options = { allow_underscores: false, allow_trailing_dot: false, allow_numeric_tld: false, + allow_wildcard: false, }; export default function isFQDN(str, options) { @@ -16,6 +17,12 @@ export default function isFQDN(str, options) { if (options.allow_trailing_dot && str[str.length - 1] === '.') { str = str.substring(0, str.length - 1); } + + /* Remove the optional wildcard before checking validity */ + if (options.allow_wildcard === true && str.indexOf('*.') === 0) { + str = str.substring(2); + } + const parts = str.split('.'); const tld = parts[parts.length - 1]; diff --git a/test/validators.js b/test/validators.js index 91794d521..e3785b63a 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1118,6 +1118,18 @@ describe('Validators', () => { ], }); }); + it('should validate FQDN with wildcard option', () => { + test({ + validator: 'isFQDN', + args: [ + { allow_wildcard: true }, + ], + valid: [ + '*.example.com', + '*.shop.example.com', + ], + }); + }); it('should validate alpha strings', () => { test({ From 6b213cf8692f8680980fe43e1d6f28f483df2a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=9D?= Date: Sat, 30 Oct 2021 13:57:49 +0800 Subject: [PATCH 075/113] fix(isMobilePhone): use a loose and future-oriented way to verify Chinese mobile phone numbers (#1682) --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 37 +++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 8b56b769f..c03067ee2 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -115,7 +115,7 @@ const phones = { 'uk-UA': /^(\+?38|8)?0\d{9}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, - 'zh-CN': /^((\+|00)86)?1([3456789][0-9]|4[579]|6[2567]|7[01235678]|9[012356789])[0-9]{8}$/, + 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, }; /* eslint-enable max-len */ diff --git a/test/validators.js b/test/validators.js index e3785b63a..9eb2d0d25 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6114,19 +6114,28 @@ describe('Validators', () => { { locale: 'zh-CN', valid: [ - '15323456787', '13523333233', - '13898728332', + '13838389438', + '14899230918', + '14999230918', + '15323456787', + '15052052020', + '16237108167', + '008616238234822', + '+8616238234822', + '16565600001', + '17269427292', + '17469427292', + '18199617480', + '19151751717', + '19651751717', '+8613238234822', '+8613487234567', '+8617823492338', '+8617823492338', - '16637108167', '+8616637108167', '+8616637108167', '+8616712341234', - '008618812341234', - '008618812341234', '+8619912341234', '+8619812341234', '+8619712341234', @@ -6135,17 +6144,25 @@ describe('Validators', () => { '+8619312341234', '+8619212341234', '+8619112341234', - '17269427292', - '16565600001', '+8617269427292', + '008618812341234', + '008618812341234', '008617269427292', - '16238234822', - '008616238234822', - '+8616238234822', + // Reserve number segments in the future. + '92138389438', + '+8692138389438', + '008692138389438', + '98199649964', + '+8698099649964', + '008698099649964', ], invalid: [ '12345', '', + '12038389438', + '12838389438', + '013838389438', + '+86-13838389438', '+08613811211114', '+008613811211114', '08613811211114', From 60dffb94086767eb003d2726be07b848f3cf193b Mon Sep 17 00:00:00 2001 From: Matteo Pierro Date: Sat, 30 Oct 2021 08:59:19 +0300 Subject: [PATCH 076/113] fix(isUrl): allow url with column and no port (#1751) --- src/lib/isURL.js | 2 +- test/validators.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 7f6e0ba5f..253b3098c 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -136,7 +136,7 @@ export default function isURL(url, options) { } } - if (port_str !== null) { + if (port_str !== null && port_str.length > 0) { port = parseInt(port_str, 10); if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) { return false; diff --git a/test/validators.js b/test/validators.js index 9eb2d0d25..7c4d965e4 100644 --- a/test/validators.js +++ b/test/validators.js @@ -535,6 +535,31 @@ describe('Validators', () => { }); }); + it('should validate URLs with column and no port', () => { + test({ + validator: 'isURL', + valid: [ + 'http://example.com:', + 'ftp://example.com:', + ], + invalid: [ + 'https://example.com:abc', + ], + }); + }); + + it('should validate sftp protocol URL containing column and no port', () => { + test({ + validator: 'isURL', + args: [{ + protocols: ['sftp'], + }], + valid: [ + 'sftp://user:pass@terminal.aws.test.nl:/incoming/things.csv', + ], + }); + }); + it('should validate protocol relative URLs', () => { test({ validator: 'isURL', From 29ed3a05e3004d086079051473eaef83e8974804 Mon Sep 17 00:00:00 2001 From: Pablo Salas Gelich <77918449+pasagedev@users.noreply.github.com> Date: Sat, 30 Oct 2021 08:00:13 +0200 Subject: [PATCH 077/113] feat(isMobilePhone): add Cuba validation (#1765) --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6e8f7117..4842d663d 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index c03067ee2..1700200b6 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -59,6 +59,7 @@ const phones = { 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/, 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/, 'es-CR': /^(\+506)?[2-8]\d{7}$/, + 'es-CU': /^(\+53|0053)?5\d{7}/, 'es-DO': /^(\+?1)?8[024]9\d{7}$/, 'es-HN': /^(\+?504)?[9|8]\d{7}$/, 'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 7c4d965e4..29d666f2d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7070,6 +7070,34 @@ describe('Validators', () => { '01234567', ], }, + { + locale: 'es-CU', + valid: [ + '+5351234567', + '005353216547', + '51234567', + '53214567', + ], + invalid: [ + '1234', + '+5341234567', + '0041234567', + '41234567', + '11234567', + '21234567', + '31234567', + '60303456', + '71234567', + '81234567', + '91234567', + '+5343216547', + '+5332165498', + '+53121234567', + '', + 'abc', + '+535123457', + ], + }, { locale: 'es-DO', valid: [ From 9347d6d70141d71c5923cfdb02e712879d00895a Mon Sep 17 00:00:00 2001 From: Sanel Hadzini <31168388+theteladras@users.noreply.github.com> Date: Sat, 30 Oct 2021 08:20:03 +0200 Subject: [PATCH 078/113] fix(isUUID): fix for null version argument supply (#1777) --- src/lib/isUUID.js | 4 ++-- test/validators.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lib/isUUID.js b/src/lib/isUUID.js index 61d938ac3..8013cfb26 100644 --- a/src/lib/isUUID.js +++ b/src/lib/isUUID.js @@ -7,8 +7,8 @@ const uuid = { all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i, }; -export default function isUUID(str, version = 'all') { +export default function isUUID(str, version) { assertString(str); - const pattern = uuid[version]; + const pattern = uuid[![undefined, null].includes(version) ? version : 'all']; return pattern && pattern.test(str); } diff --git a/test/validators.js b/test/validators.js index 29d666f2d..64aa67d25 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4450,6 +4450,34 @@ describe('Validators', () => { 'AAAAAAAA-1111-1111-AAAG-111111111111', ], }); + test({ + validator: 'isUUID', + args: [undefined], + valid: [ + 'A117FBC9-4BED-3078-CF07-9141BA07C9F3', + 'A117FBC9-4BED-5078-AF07-9141BA07C9F3', + ], + invalid: [ + '', + 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3', + 'A987FBC94BED3078CF079141BA07C9F3', + 'A11AAAAA-1111-1111-AAAG-111111111111', + ], + }); + test({ + validator: 'isUUID', + args: [null], + valid: [ + 'A127FBC9-4BED-3078-CF07-9141BA07C9F3', + ], + invalid: [ + '', + 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3', + 'A127FBC9-4BED-3078-CF07-9141BA07C9F3xxx', + '912859', + 'A12AAAAA-1111-1111-AAAG-111111111111', + ], + }); test({ validator: 'isUUID', args: [3], From 050a424e1bda06a06b1f5e4a5ca1dd1d9a8ceea4 Mon Sep 17 00:00:00 2001 From: Hammad Javed Date: Sat, 30 Oct 2021 11:22:38 +0500 Subject: [PATCH 079/113] fix(isMobilePhone): regex for Pakistan(PK) (#1778) * Fix Mobile Phone Regex Pakistan(PK) Update the regex to validate mobile numbers correctly for Pakistan * Add tests for mobile number validation locale en-PK (Pakistan) * Linting fix * Update src/lib/isMobilePhone.js Update pakistan mobile regex according to suggestion Co-authored-by: Sarhan Aissi * Update tests for PK phone numbers Co-authored-by: Sarhan Aissi --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 1700200b6..8563d3b51 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -43,7 +43,7 @@ const phones = { '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-PK': /^((00|\+)?92|0)3[0-6]\d{8}$/, 'en-PH': /^(09|\+639)\d{9}$/, 'en-RW': /^(\+?250|0)?[7]\d{8}$/, 'en-SG': /^(\+65)?[3689]\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 64aa67d25..367c73e7d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8056,6 +8056,26 @@ describe('Validators', () => { 'NotANumber', ], }, + { + locale: 'en-PK', + valid: [ + '+923412877421', + '+923001234567', + '00923001234567', + '923001234567', + '03001234567', + ], + invalid: [ + '+3001234567', + '+933001234567', + '+924001234567', + '+92300123456720', + '030012345672', + '30012345673', + '0030012345673', + '3001234567', + ], + }, ]; let allValid = []; From 5ed7db173f7e7619ec7e46269239bf10dda5009e Mon Sep 17 00:00:00 2001 From: Ishara Madhavi Date: Sat, 30 Oct 2021 11:59:28 +0530 Subject: [PATCH 080/113] fix(isMobilePhone): update Sri Lanka locale (#1785) --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 8563d3b51..2db323db3 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -105,7 +105,7 @@ const phones = { 'pt-AO': /^(\+244)\d{9}$/, 'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/, 'ru-RU': /^(\+?7|8)?9\d{9}$/, - 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/, + 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/, '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}$/, 'sq-AL': /^(\+355|0)6[789]\d{6}$/, diff --git a/test/validators.js b/test/validators.js index 367c73e7d..8481f0e21 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6841,14 +6841,13 @@ describe('Validators', () => { '0786642116', '078 7642116', '078-7642116', - + '0749994567', ], invalid: [ '9912349956789', '12345', '1678123456', '0731234567', - '0749994567', '0797878674', ], }, From dc9f84386f2d52ba90479b6849b112971939d66e Mon Sep 17 00:00:00 2001 From: Nimantha Cooray <54179737+nimanthadilz@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:01:29 +0530 Subject: [PATCH 081/113] feat(isIdentityCard): add 'LK' (Sri Lanka) locale (#1786) * Implement isIdentityCard LK(Sri Lanka) locale * Add tests for isIdentityCard LK locale * Update README.md for the isIdentityCard LK locale * Change let to const Co-authored-by: Sarhan Aissi Co-authored-by: Sarhan Aissi --- README.md | 2 +- src/lib/isIdentityCard.js | 8 ++++++++ test/validators.js | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4842d663d..63bc61456 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIBAN(str)** | check if a string is a IBAN (International Bank Account Number). -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['PL', 'ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['LK', 'PL', 'ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.

`options` is an object which can contain the keys `allow_hyphens`. Defaults to first format . If allow_hyphens is set to true, the validator will validate the second format. **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). diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 8ea15e262..b004803b8 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -160,6 +160,14 @@ const validators = { } return str[12] === ((11 - (sum % 11)) % 10).toString(); }, + LK: (str) => { + const old_nic = /^[1-9]\d{8}[vx]$/i; + const new_nic = /^[1-9]\d{11}$/i; + + if (str.length === 10 && old_nic.test(str)) return true; + else if (str.length === 12 && new_nic.test(str)) return true; + return false; + }, 'he-IL': (str) => { const DNI = /^\d{9}$/; diff --git a/test/validators.js b/test/validators.js index 8481f0e21..3937eaadf 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4751,6 +4751,27 @@ describe('Validators', () => { it('should validate identity cards', () => { const fixtures = [ + { + locale: 'LK', + valid: [ + '722222222v', + '722222222V', + '993151225x', + '993151225X', + '188888388x', + '935632124V', + '199931512253', + '200023125632', + ], + invalid: [ + '023125648V', + '023345621v', + '021354211X', + '055321231x', + '02135465462', + '199931512253X', + ], + }, { locale: 'PL', valid: [ From 84512066ce6afab9d8d525235cec132d7dc544a4 Mon Sep 17 00:00:00 2001 From: Nimantha Cooray <54179737+nimanthadilz@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:04:02 +0530 Subject: [PATCH 082/113] feat(isPostalCode): add `LK` (Sri Lanka) locale (#1788) * Add `LK` locale to `isPostalCode` * Add tests for `LK` locale of `isPostalCode` * Update README.md --- README.md | 2 +- src/lib/isPostalCode.js | 1 + test/validators.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63bc61456..ec60833d4 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Validator | Description **isOctal(str)** | check if the string is a valid octal number. **isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'ID', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'MZ', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'KR', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). +**isPostalCode(str, locale)** | check if the string is a postal code,

(locale is one of `[ 'AD', 'AT', 'AU', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'KR', 'LI', 'LK', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. **isRgbColor(str [, includePercentValues])** | check if the string is a rgb or rgba color.

`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false. **isSemVer(str)** | check if the string is a Semantic Versioning Specification (SemVer). diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index 915c27f2b..7ef17abcf 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -46,6 +46,7 @@ const patterns = { LT: /^LT\-\d{5}$/, LU: fourDigit, LV: /^LV\-\d{4}$/, + LK: fiveDigit, MX: fiveDigit, MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/, MY: fiveDigit, diff --git a/test/validators.js b/test/validators.js index 3937eaadf..664b6aa30 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10154,6 +10154,20 @@ describe('Validators', () => { 'ab1234', ], }, + { + locale: 'LK', + valid: [ + '11500', + '22200', + '10370', + '43000', + ], + invalid: [ + '1234', + '789389', + '982', + ], + }, ]; let allValid = []; From 526417af2a9a4ef17a23ef952690ab853ce20cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Tyrkk=C3=B6?= Date: Sat, 30 Oct 2021 09:36:21 +0300 Subject: [PATCH 083/113] feat(isLicensePlate): add finnish locale (#1790) Co-authored-by: Markus --- README.md | 2 +- src/lib/isLicensePlate.js | 1 + test/validators.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec60833d4..e5b683550 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Validator | Description **isJWT(str)** | check if the string is valid JWT token. **isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.

`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format. **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. -**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR']` or `any`) +**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'fi-FI', pt-PT', 'sq-AL', 'pt-BR']` or `any`) **isLocale(str)** | check if the string is a locale **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_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index d81995bff..d6b27a5ad 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -6,6 +6,7 @@ const validators = { 'de-DE': str => /^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS|TR|TÜ|UM|PZ|TP|UE|UN|UH|MN|KK|VB|V|AE|PL|RC|VG|GW|PW|VR|VK|KB|WA|WT|BE|WM|WE|AP|MO|WW|FB|WZ|WI|WB|JE|WF|WO|W|WÜ|BL|Z|GC)[- ]?[A-Z]{1,2}[- ]?\d{1,4}|(AIC|FDB|ABG|SLN|SAW|KLZ|BUL|ESB|NAB|SUL|WST|ABI|AZE|BTF|KÖT|DKB|FEU|ROT|ALZ|SMÜ|WER|AUR|NOR|DÜW|BRK|HAB|TÖL|WOR|BAD|BAR|BER|BIW|EBS|KEM|MÜB|PEG|BGL|BGD|REI|WIL|BKS|BIR|WAT|BOR|BOH|BOT|BRB|BLK|HHM|NEB|NMB|WSF|LEO|HDL|WMS|WZL|BÜS|CHA|KÖZ|ROD|WÜM|CLP|NEC|COC|ZEL|COE|CUX|DAH|LDS|DEG|DEL|RSL|DLG|DGF|LAN|HEI|MED|DON|KIB|ROK|JÜL|MON|SLE|EBE|EIC|HIG|WBS|BIT|PRÜ|LIB|EMD|WIT|ERH|HÖS|ERZ|ANA|ASZ|MAB|MEK|STL|SZB|FDS|HCH|HOR|WOL|FRG|GRA|WOS|FRI|FFB|GAP|GER|BRL|CLZ|GTH|NOH|HGW|GRZ|LÖB|NOL|WSW|DUD|HMÜ|OHA|KRU|HAL|HAM|HBS|QLB|HVL|NAU|HAS|EBN|GEO|HOH|HDH|ERK|HER|WAN|HEF|ROF|HBN|ALF|HSK|USI|NAI|REH|SAN|KÜN|ÖHR|HOL|WAR|ARN|BRG|GNT|HOG|WOH|KEH|MAI|PAR|RID|ROL|KLE|GEL|KUS|KYF|ART|SDH|LDK|DIL|MAL|VIB|LER|BNA|GHA|GRM|MTL|WUR|LEV|LIF|STE|WEL|LIP|VAI|LUP|HGN|LBZ|LWL|PCH|STB|DAN|MKK|SLÜ|MSP|TBB|MGH|MTK|BIN|MSH|EIL|HET|SGH|BID|MYK|MSE|MST|MÜR|WRN|MEI|GRH|RIE|MZG|MIL|OBB|BED|FLÖ|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str), 'de-LI': str => /^FL[- ]?\d{1,5}[UZ]?$/.test(str), + 'fi-FI': str => /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str), 'pt-PT': str => /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str), 'sq-AL': str => diff --git a/test/validators.js b/test/validators.js index 664b6aa30..89b93058f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -11095,6 +11095,39 @@ describe('Validators', () => { 'FS AB 1234 A', ], }); + test({ + validator: 'isLicensePlate', + args: ['fi-FI'], + valid: [ + 'ABC-123', + 'ABC 123', + 'ABC123', + 'A100', + 'A 100', + 'A-100', + 'C10001', + 'C 10001', + 'C-10001', + '123-ABC', + '123 ABC', + '123ABC', + '123-A', + '123 A', + '123A', + '199AA', + '199 AA', + '199-AA', + ], + invalid: [ + ' ', + 'A-1', + 'A1A-100', + '1-A-2', + 'C1234567', + 'A B C 1 2 3', + 'abc-123', + ], + }); test({ validator: 'isLicensePlate', args: ['sq-AL'], From 6eed6a4ec8dcf220fecafb59655b21cf9df37bd4 Mon Sep 17 00:00:00 2001 From: Matteo Pierro Date: Sat, 30 Oct 2021 09:52:35 +0300 Subject: [PATCH 084/113] fix(isFQDN): check more special chars (#1799) fixes #1087 --- src/lib/isFQDN.js | 6 +++--- test/validators.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib/isFQDN.js b/src/lib/isFQDN.js index b82b08941..4a04cf34e 100644 --- a/src/lib/isFQDN.js +++ b/src/lib/isFQDN.js @@ -32,12 +32,12 @@ export default function isFQDN(str, options) { return false; } - if (!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) { + if (!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) { return false; } - // disallow spaces && special characers - if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) { + // disallow spaces + if (/\s/.test(tld)) { return false; } } diff --git a/test/validators.js b/test/validators.js index 89b93058f..af8aba417 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1099,6 +1099,18 @@ describe('Validators', () => { 'domain.com/', '/more.com', 'domain.com�', + 'domain.co\u00A0m', + 'domain.co\u1680m', + 'domain.co\u2006m', + 'domain.co\u2028m', + 'domain.co\u2029m', + 'domain.co\u202Fm', + 'domain.co\u205Fm', + 'domain.co\u3000m', + 'domain.com\uDC00', + 'domain.co\uEFFFm', + 'domain.co\uFDDAm', + 'domain.co\uFFF4m', 'domain.com©', 'example.0', '192.168.0.9999', From a837e6fbb0aec52ff31ff5e328e1adca8c631d77 Mon Sep 17 00:00:00 2001 From: Ronan Date: Sat, 30 Oct 2021 08:55:38 +0200 Subject: [PATCH 085/113] fix(isPassportNumber): update Poland country code (#1809) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated Poland Country Code * Updated PO to PL in validator.js * Changed PO to PL in README.md * Typo in README.md Co-authored-by: Ronan Doudiès --- README.md | 2 +- src/lib/isPassportNumber.js | 2 +- test/validators.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e5b683550..350c1b202 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ Validator | Description **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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. **isOctal(str)** | check if the string is a valid octal number. -**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'ID', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'MZ', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. +**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'ID', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'MZ', 'NL', 'PL', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **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', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'KR', 'LI', 'LK', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'TH', '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`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 76284b12f..949e38211 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -47,7 +47,7 @@ const passportRegexByCountryCode = { MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/, // MOZAMBIQUE MY: /^[AHK]\d{8}$/, // MALAYSIA NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS - PO: /^[A-Z]{2}\d{7}$/, // POLAND + PL: /^[A-Z]{2}\d{7}$/, // POLAND PT: /^[A-Z]\d{6}$/, // PORTUGAL RO: /^\d{8,9}$/, // ROMANIA RU: /^\d{2}\d{2}\d{6}$/, // RUSSIAN FEDERATION diff --git a/test/validators.js b/test/validators.js index af8aba417..decb09ab0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3000,7 +3000,7 @@ describe('Validators', () => { test({ validator: 'isPassportNumber', - args: ['PO'], + args: ['PL'], valid: [ 'ZS 0000177', 'AN 3000011', From ba4106fe47bbd207b7cced49594e81f8307d8872 Mon Sep 17 00:00:00 2001 From: Daniel Tiringer <53534182+danielTiringer@users.noreply.github.com> Date: Sat, 30 Oct 2021 07:00:34 +0000 Subject: [PATCH 086/113] fix(isMobilePhone): update Hungarian locale (#1826) * Add internal country code option * Add new area code options * Add tests to hu mobile number validation --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 2db323db3..6f486a101 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -81,7 +81,7 @@ const phones = { 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/, 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/, 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/, - 'hu-HU': /^(\+?36)(20|30|70)\d{7}$/, + 'hu-HU': /^(\+?36|06)(20|30|31|50|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}$/, 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/, diff --git a/test/validators.js b/test/validators.js index decb09ab0..596b585ae 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6109,6 +6109,19 @@ describe('Validators', () => { '064349089895623459', ], }, + { + locale: 'hu-HU', + valid: [ + '06301234567', + '+36201234567', + '06701234567', + ], + invalid: [ + '1234', + '06211234567', + '+3620123456', + ], + }, { locale: 'mz-MZ', valid: [ From c42b2d9a7dd018b0724f9bbd6be4fbc7999ec5ca Mon Sep 17 00:00:00 2001 From: Bijay Singh Date: Sat, 30 Oct 2021 14:29:47 +0530 Subject: [PATCH 087/113] feat(isMobilePhone): add Bermuda en-BM locale (#1769) * Added validation for Bermuda on isMobilePhone * changed regex for bermuda to disable landline no --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 350c1b202..79479d9a9 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-BM', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 6f486a101..a6a0a85d7 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -31,6 +31,7 @@ const phones = { 'de-LU': /^(\+352)?((6\d1)\d{6})$/, 'el-GR': /^(\+?30|0)?(69\d{8})$/, 'en-AU': /^(\+?61|0)4\d{8}$/, + 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}))/, 'en-GB': /^(\+?44|0)7\d{9}$/, 'en-GG': /^(\+?44|0)1481\d{6}$/, 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28|55|59)\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 596b585ae..43c11e47b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6287,6 +6287,26 @@ describe('Validators', () => { '0-987123456', ], }, + { + locale: 'en-BM', + valid: [ + '+14417974653', + '14413986653', + '4415370973', + '+14415005489', + ], + invalid: [ + '85763287', + '+14412020436', + '+14412236546', + '+14418245567', + '+14416546789', + '44087635627', + '+4418970973', + '', + '+1441897465', + ], + }, { locale: 'en-ZA', valid: [ From 7835db1525668dc52eada233c404bb0cde166f82 Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Sat, 30 Oct 2021 12:04:28 +0300 Subject: [PATCH 088/113] fix(docs): add missing locale (#1845) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79479d9a9..1feccc176 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-BM', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-BM', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. From 28f899deba737d97846af9634491dd197d711e72 Mon Sep 17 00:00:00 2001 From: Miguel Savignano Date: Sat, 30 Oct 2021 11:12:26 +0200 Subject: [PATCH 089/113] feat(isUrl): urls with empty user (#1833) * allow urls with empty user * use array extract * reuse auth split --- src/lib/isURL.js | 6 +++++- test/validators.js | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 253b3098c..aa6222a90 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -111,13 +111,17 @@ export default function isURL(url, options) { if (options.disallow_auth) { return false; } - if (split[0] === '' || split[0].substr(0, 1) === ':') { + if (split[0] === '') { return false; } auth = split.shift(); if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) { return false; } + const [user, password] = auth.split(':'); + if (user === '' && password === '') { + return false; + } } hostname = split.join('@'); diff --git a/test/validators.js b/test/validators.js index 43c11e47b..affb8f776 100644 --- a/test/validators.js +++ b/test/validators.js @@ -364,6 +364,7 @@ describe('Validators', () => { 'http://www.foobar.com/~foobar', 'http://user:pass@www.foobar.com/', 'http://user:@www.foobar.com/', + 'http://:pass@www.foobar.com/', 'http://user@www.foobar.com', 'http://127.0.0.1/', 'http://10.0.0.0/', From 3fcf768f39eee371c7f7859db0495a114dd63d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Tyrkk=C3=B6?= Date: Sat, 30 Oct 2021 12:34:38 +0300 Subject: [PATCH 090/113] fix(unescape): fixed bug where intermediate string contains escaped characters (#1835) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed bug where intermediate string contains escaped characters * Added reference to issue Co-authored-by: Markus Tyrkkö Co-authored-by: Markus --- src/lib/unescape.js | 9 ++++++--- test/sanitizers.js | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/unescape.js b/src/lib/unescape.js index 213a0f70b..feb255ac0 100644 --- a/src/lib/unescape.js +++ b/src/lib/unescape.js @@ -2,12 +2,15 @@ import assertString from './util/assertString'; export default function unescape(str) { assertString(str); - return (str.replace(/&/g, '&') - .replace(/"/g, '"') + return (str.replace(/"/g, '"') .replace(/'/g, "'") .replace(/</g, '<') .replace(/>/g, '>') .replace(///g, '/') .replace(/\/g, '\\') - .replace(/`/g, '`')); + .replace(/`/g, '`') + .replace(/&/g, '&')); + // & replacement has to be the last one to prevent + // bugs with intermediate strings containing escape sequences + // See: https://github.com/validatorjs/validator.js/issues/1827 } diff --git a/test/sanitizers.js b/test/sanitizers.js index 00ec35ab9..ecb0e128f 100644 --- a/test/sanitizers.js +++ b/test/sanitizers.js @@ -184,6 +184,9 @@ describe('Sanitizers', () => { 'Backtick: `': 'Backtick: `', + + 'Escaped string: &lt;': + 'Escaped string: <', }, }); }); From 22018690f3969339b1133464682671437ef5d67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Tyrkk=C3=B6?= Date: Sat, 30 Oct 2021 12:39:32 +0300 Subject: [PATCH 091/113] feat: added finnish locale to isAlpha and isAlphanumeric (#1837) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Markus Tyrkkö --- README.md | 4 ++-- src/lib/alpha.js | 2 ++ test/validators.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1feccc176..5b00ceb71 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ Validator | Description **contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false}`.
`ignoreCase` specified whether the case of the substring be same or not. **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, options])** | 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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', 'hi-IN', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. -**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', 'hi-IN', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlpha(str [, locale, options])** | 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', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

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', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. **isAscii(str)** | check if the string contains ASCII chars only. **isBase32(str)** | check if a string is base32 encoded. **isBase58(str)** | check if a string is base58 encoded. diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 27d3fbc6c..d663eded0 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -8,6 +8,7 @@ export const alpha = { 'el-GR': /^[Α-ώ]+$/i, 'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i, 'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i, + 'fi-FI': /^[A-ZÅÄÖ]+$/i, 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i, 'nb-NO': /^[A-ZÆØÅ]+$/i, @@ -42,6 +43,7 @@ export const alphanumeric = { 'de-DE': /^[0-9A-ZÄÖÜß]+$/i, 'el-GR': /^[0-9Α-ω]+$/i, 'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i, + 'fi-FI': /^[0-9A-ZÅÄÖ]+$/i, 'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i, 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i, diff --git a/test/validators.js b/test/validators.js index affb8f776..33b85a7a1 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1497,6 +1497,24 @@ describe('Validators', () => { }); }); + it('should validate finnish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['fi-FI'], + valid: [ + 'äiti', + 'Öljy', + 'Åke', + 'testÖ', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'äöå123', + '', + ], + }); + }); + it('should validate kurdish alpha strings', () => { test({ validator: 'isAlpha', @@ -1981,6 +1999,24 @@ describe('Validators', () => { }); }); + it('should validate finnish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['fi-FI'], + valid: [ + 'äiti124', + 'ÖLJY1234', + '123Åke', + '451åå23', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'foo!!', + '', + ], + }); + }); + it('should validate german alphanumeric strings', () => { test({ validator: 'isAlphanumeric', From 57cc14e1dd9c909da2b6751d31559240e249c31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Tyrkk=C3=B6?= Date: Sat, 30 Oct 2021 12:41:21 +0300 Subject: [PATCH 092/113] feat(isIdentityCard): add finnish locale (#1838) Co-authored-by: Markus --- README.md | 2 +- src/lib/isIdentityCard.js | 20 ++++++++++++++++++++ test/validators.js | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b00ceb71..54806336b 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIBAN(str)** | check if a string is a IBAN (International Bank Account Number). -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['LK', 'PL', 'ES', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['LK', 'PL', 'ES', 'FI', 'IN', 'IT', 'IR', 'MZ', 'NO', 'TH', 'zh-TW', 'he-IL', 'ar-LY', 'ar-TN', 'zh-CN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIMEI(str [, options]))** | check if the string is a valid IMEI number. Imei should be of format `###############` or `##-######-######-#`.

`options` is an object which can contain the keys `allow_hyphens`. Defaults to first format . If allow_hyphens is set to true, the validator will validate the second format. **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). diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index b004803b8..9dc1302ad 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -63,6 +63,26 @@ const validators = { return sanitized.endsWith(controlDigits[number % 23]); }, + FI: (str) => { + // https://dvv.fi/en/personal-identity-code#:~:text=control%20character%20for%20a-,personal,-identity%20code%20calculated + assertString(str); + + if (str.length !== 11) { + return false; + } + + if (!str.match(/^\d{6}[\-A\+]\d{3}[0-9ABCDEFHJKLMNPRSTUVWXY]{1}$/)) { + return false; + } + + const checkDigits = '0123456789ABCDEFHJKLMNPRSTUVWXY'; + + const idAsNumber = (parseInt(str.slice(0, 6), 10) * 1000) + parseInt(str.slice(7, 10), 10); + const remainder = idAsNumber % 31; + const checkDigit = checkDigits[remainder]; + + return checkDigit === str.slice(10, 11); + }, IN: (str) => { const DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/; diff --git a/test/validators.js b/test/validators.js index 33b85a7a1..d737f2280 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4874,6 +4874,20 @@ describe('Validators', () => { 'Z1234567C', ], }, + { + locale: 'FI', + valid: [ + '131052-308T', // People born in 1900s + '131052A308T', // People born in 2000s + '131052+308T', // People born in 1800s + '131052-313Y', + ], + invalid: [ + '131052308T', + '131052-308T ', + '131052-308A', + ], + }, { locale: 'IN', valid: [ From 7bee611cd87f2311d1fe82c416a40941005c696f Mon Sep 17 00:00:00 2001 From: Luis Romero Date: Sat, 30 Oct 2021 04:54:46 -0500 Subject: [PATCH 093/113] add CDN use option with unpkg (#1844) closes #1507 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 54806336b..cf913a202 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,12 @@ The library can also be installed through [bower][bower] $ bower install validator-js ``` +CDN + +```html + +``` + ## Contributors [Become a backer](https://opencollective.com/validatorjs#backer) From de1cb296dc55444423c155d84e5307819b6ec8c3 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Sat, 30 Oct 2021 11:57:11 +0200 Subject: [PATCH 094/113] fix: Russian passport number regex (#1810) * fix: Russian passport number regex fixes #1807 --- src/lib/isPassportNumber.js | 2 +- test/validators.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 949e38211..4c38bfbbe 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -50,7 +50,7 @@ const passportRegexByCountryCode = { PL: /^[A-Z]{2}\d{7}$/, // POLAND PT: /^[A-Z]\d{6}$/, // PORTUGAL RO: /^\d{8,9}$/, // ROMANIA - RU: /^\d{2}\d{2}\d{6}$/, // RUSSIAN FEDERATION + RU: /^\d{9}$/, // RUSSIAN FEDERATION SE: /^\d{8}$/, // SWEDEN SL: /^(P)[A-Z]\d{7}$/, // SLOVANIA SK: /^[0-9A-Z]\d{7}$/, // SLOVAKIA diff --git a/test/validators.js b/test/validators.js index d737f2280..5edb735d6 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3078,14 +3078,16 @@ describe('Validators', () => { validator: 'isPassportNumber', args: ['RU'], valid: [ - '26 32 636829', - '0121 345321', - '4398636928', + '2 32 636829', + '012 345321', + '439863692', ], invalid: [ - 'AZ 2R YU46J', - '012A 3D5321', - 'SF233D532T', + 'A 2R YU46J0', + '01A 3D5321', + 'SF233D53T', + '12345678', + '1234567890', ], }); From 57738693d97e087200c929237c1d57cf0a69218b Mon Sep 17 00:00:00 2001 From: Dave Borghuis Date: Sat, 30 Oct 2021 12:01:48 +0200 Subject: [PATCH 095/113] feat(isVAT): add dutch NL locale (#1825) for hacktober #1742 if you want to extend it more check : https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s21.html --- README.md | 2 +- src/lib/isVAT.js | 1 + test/validators.js | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cf913a202..93b5fd18f 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ Validator | Description **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_port: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, allow_fragments: true, allow_query_components: true, disallow_auth: false, validate_length: true }`.

require_protocol - if set as true isURL will return false if protocol is not present in the URL.
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
protocols - valid protocols can be modified with this option.
require_host - if set as false isURL will not check if host is present in the URL.
require_port - if set as true isURL will check if port is present in the URL.
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.
allow_fragments - if set as false isURL will return false if fragments are present.
allow_query_components - if set as false isURL will return false if query components are present.
validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). **isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). **isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. -**isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

Available country codes: `[ 'GB', 'IT' ]`. +**isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

Available country codes: `[ 'GB', 'IT','NL' ]`. **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')`. diff --git a/src/lib/isVAT.js b/src/lib/isVAT.js index 549bf336f..884b066ff 100644 --- a/src/lib/isVAT.js +++ b/src/lib/isVAT.js @@ -3,6 +3,7 @@ import assertString from './util/assertString'; export const vatMatchers = { GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/, IT: /^(IT)?[0-9]{11}$/, + NL: /^(NL)?[0-9]{9}B[0-9]{2}$/, }; export default function isVAT(str, countryCode) { diff --git a/test/validators.js b/test/validators.js index 5edb735d6..1b92f3a64 100644 --- a/test/validators.js +++ b/test/validators.js @@ -11310,7 +11310,7 @@ describe('Validators', () => { ], }); }); - it('should validate english VAT numbers', () => { + it('should validate VAT numbers', () => { test({ validator: 'isVAT', args: ['GB'], @@ -11340,7 +11340,6 @@ describe('Validators', () => { 'GBHA499', ], }); - test({ validator: 'isVAT', args: ['IT'], @@ -11356,7 +11355,21 @@ describe('Validators', () => { 'IT123456789', ], }); - + test({ + validator: 'isVAT', + args: ['NL'], + valid: [ + 'NL123456789B10', + '123456789B10', + ], + invalid: [ + 'NL12345678 910', + 'NL 123456789101', + 'NL123456789B1', + 'GB12345678910', + 'NL123456789', + ], + }); test({ validator: 'isVAT', args: ['invalidCountryCode'], From f2381e0fe046a1dc4a6906963425f444bc5ab360 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sun, 31 Oct 2021 01:03:44 -0400 Subject: [PATCH 096/113] feat: (isMobilePhone): add Cameroon fr-CM locale (#1772) * Add Cameroon validation regex I have added a regex for validating Cameroonian mobile numbers which should work. I'm not super comfortable with regular expressions, so if I have screwed something up, please let me know. I have done some basic testing and it has functioned fine thus far. * Update README to include fr-CM in isMobilePhone * Add (very) basic testing for Cameroonian mobile number * Fix missing brace (whoops!) * Fix commas (I hope) * Fix sloppy tests Fix my sloppy tests. I'm really tired and probably should not be working on this, but I accidentally added an extra digit while typing. * Update regex for correctness Add mobile prefix (6) to regex, remove space allowance, and optimize regex * Update tests for correctness * Remove invalid space Sorry! * Rerun failed tests (internal server error) --- src/lib/isMobilePhone.js | 1 + test/validators.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index a6a0a85d7..d86712a87 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -76,6 +76,7 @@ const phones = { 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/, 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, + 'fr-CM': /^(\+?237)6[0-9]{8}$/, 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, diff --git a/test/validators.js b/test/validators.js index 1b92f3a64..8d566702b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7568,6 +7568,21 @@ describe('Validators', () => { '088-320000', ], }, + { + locale: 'fr-CM', + valid: [ + '+237677936141', + '237623456789', + '+237698124842', + '237693029202', + ], + invalid: [ + 'NotANumber', + '+(703)-572-2920', + '+237 623 45 67 890', + '+2379981247429', + ], + }, { locale: 'ko-KR', valid: [ From 769f6d55d3ca5c7415026d467d3d89e584ac68cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Tyrkk=C3=B6?= Date: Sun, 31 Oct 2021 07:04:37 +0200 Subject: [PATCH 097/113] feat(contains): add possibility to check that string contains seed multiple times (#1836) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added feature to require minimum number of occurrences for the seed in 'contains' * Changed regex to split Co-authored-by: Markus Tyrkkö Co-authored-by: Markus --- README.md | 2 +- src/lib/contains.js | 10 +++++++--- test/validators.js | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 93b5fd18f..9c6bef836 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Here is a list of the validators currently available. Validator | Description --------------------------------------- | -------------------------------------- -**contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false}`.
`ignoreCase` specified whether the case of the substring be same or not. +**contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false, minOccurrences: 1 }`.
Options:
`ignoreCase`: Ignore case when doing comparison, default false
`minOccurences`: Minimum number of occurrences for the seed in the string. Defaults to 1. **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, options])** | 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', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', '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`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. diff --git a/src/lib/contains.js b/src/lib/contains.js index ec083fa18..7be314b04 100644 --- a/src/lib/contains.js +++ b/src/lib/contains.js @@ -4,12 +4,16 @@ import merge from './util/merge'; const defaulContainsOptions = { ignoreCase: false, + minOccurrences: 1, }; export default function contains(str, elem, options) { assertString(str); options = merge(options, defaulContainsOptions); - return options.ignoreCase ? - str.toLowerCase().indexOf(toString(elem).toLowerCase()) >= 0 : - str.indexOf(toString(elem)) >= 0; + + if (options.ignoreCase) { + return str.toLowerCase().split(toString(elem).toLowerCase()).length > options.minOccurrences; + } + + return str.split(toString(elem)).length > options.minOccurrences; } diff --git a/test/validators.js b/test/validators.js index 8d566702b..0ab187ceb 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4327,6 +4327,15 @@ describe('Validators', () => { valid: ['Foo', 'FOObar', 'BAZfoo'], invalid: ['bar', 'fobar', 'baxoof'], }); + + test({ + validator: 'contains', + args: ['foo', { + minOccurrences: 2, + }], + valid: ['foofoofoo', '12foo124foo', 'fofooofoooofoooo', 'foo1foo'], + invalid: ['foo', 'foobar', 'Fooofoo', 'foofo'], + }); }); it('should validate strings against a pattern', () => { From af2b43c769a3bb9013fe12f3f3747f8124756664 Mon Sep 17 00:00:00 2001 From: Sanel Hadzini <31168388+theteladras@users.noreply.github.com> Date: Sun, 31 Oct 2021 06:14:16 +0100 Subject: [PATCH 098/113] feat(isUUID): add support for validation of version v1 and v2 (#1848) * fix(isUUID) for null version argument supply * improve(isUUID) validation for version 1 and 2 --- README.md | 2 +- src/lib/isUUID.js | 4 +++- test/validators.js | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c6bef836..7273b72c6 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ Validator | Description **isStrongPassword(str [, options])** | Check if a password is strong or not. Allows for custom requirements or scoring rules. If `returnScore` is true, then the function returns an integer score for the password rather than a boolean.
Default options:
`{ minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1, returnScore: false, pointsPerUnique: 1, pointsPerRepeat: 0.5, pointsForContainingLower: 10, pointsForContainingUpper: 10, pointsForContainingNumber: 10, pointsForContainingSymbol: 10 }` **isTaxID(str, locale)** | Check if the given value is a valid Tax Identification Number. Default locale is `en-US`.

More info about exact TIN support can be found in `src/lib/isTaxID.js`

Supported locales: `[ 'bg-BG', 'cs-CZ', 'de-AT', 'de-DE', 'dk-DK', 'el-CY', 'el-GR', 'en-GB', 'en-IE', 'en-US', 'es-ES', 'et-EE', 'fi-FI', 'fr-BE', 'fr-FR', 'fr-LU', 'hr-HR', 'hu-HU', 'it-IT', 'lb-LU', 'lt-LT', 'lv-LV' 'mt-MT', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE' ]` **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_port: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, allow_fragments: true, allow_query_components: true, disallow_auth: false, validate_length: true }`.

require_protocol - if set as true isURL will return false if protocol is not present in the URL.
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
protocols - valid protocols can be modified with this option.
require_host - if set as false isURL will not check if host is present in the URL.
require_port - if set as true isURL will check if port is present in the URL.
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.
allow_fragments - if set as false isURL will return false if fragments are present.
allow_query_components - if set as false isURL will return false if query components are present.
validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). -**isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). +**isUUID(str [, version])** | check if the string is a UUID (version 1, 2, 3, 4 or 5). **isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. **isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

Available country codes: `[ 'GB', 'IT','NL' ]`. **isWhitelisted(str, chars)** | checks characters if they appear in the whitelist. diff --git a/src/lib/isUUID.js b/src/lib/isUUID.js index 8013cfb26..c026ca78c 100644 --- a/src/lib/isUUID.js +++ b/src/lib/isUUID.js @@ -1,6 +1,8 @@ import assertString from './util/assertString'; const uuid = { + 1: /^[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, + 2: /^[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, 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, @@ -10,5 +12,5 @@ const uuid = { export default function isUUID(str, version) { assertString(str); const pattern = uuid[![undefined, null].includes(version) ? version : 'all']; - return pattern && pattern.test(str); + return !!pattern && pattern.test(str); } diff --git a/test/validators.js b/test/validators.js index 0ab187ceb..e2ecf9959 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4538,6 +4538,35 @@ describe('Validators', () => { 'A12AAAAA-1111-1111-AAAG-111111111111', ], }); + test({ + validator: 'isUUID', + args: [1], + valid: [ + 'E034B584-7D89-11E9-9669-1AECF481A97B', + ], + invalid: [ + 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3', + 'AAAAAAAA-1111-2222-AAAG', + 'AAAAAAAA-1111-2222-AAAG-111111111111', + 'A987FBC9-4BED-4078-8F07-9141BA07C9F3', + 'A987FBC9-4BED-5078-AF07-9141BA07C9F3', + ], + }); + test({ + validator: 'isUUID', + args: [2], + valid: [ + 'A987FBC9-4BED-2078-CF07-9141BA07C9F3', + ], + invalid: [ + '', + 'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3', + '11111', + 'AAAAAAAA-1111-1111-AAAG-111111111111', + 'A987FBC9-4BED-4078-8F07-9141BA07C9F3', + 'A987FBC9-4BED-5078-AF07-9141BA07C9F3', + ], + }); test({ validator: 'isUUID', args: [3], @@ -4589,6 +4618,18 @@ describe('Validators', () => { 'A987FBC9-4BED-3078-CF07-9141BA07C9F3', ], }); + test({ + validator: 'isUUID', + args: [6], + valid: [], + invalid: [ + '987FBC97-4BED-1078-AF07-9141BA07C9F3', + '987FBC97-4BED-2078-AF07-9141BA07C9F3', + '987FBC97-4BED-3078-AF07-9141BA07C9F3', + '987FBC97-4BED-4078-AF07-9141BA07C9F3', + '987FBC97-4BED-5078-AF07-9141BA07C9F3', + ], + }); }); it('should validate a string that is in another string or array', () => { From 01d3da3e630e1232dbd4ddd090dd16e2a8bd3c66 Mon Sep 17 00:00:00 2001 From: Magnus Sustad <56775490+mgnss@users.noreply.github.com> Date: Sun, 31 Oct 2021 06:17:25 +0100 Subject: [PATCH 099/113] feat(isMobilePhone): add Tajikistan tg-TJ locale (#1846) --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7273b72c6..473f04aec 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-BM', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-BM', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index d86712a87..b9d14f635 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -113,6 +113,7 @@ const phones = { 'sq-AL': /^(\+355|0)6[789]\d{6}$/, 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/, 'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/, + 'tg-TJ': /^(\+?992)?[5][5]\d{7}$/, 'th-TH': /^(\+66|66|0)\d{9}$/, 'tr-TR': /^(\+?90|0)?5\d{9}$/, 'uk-UA': /^(\+?38|8)?0\d{9}$/, diff --git a/test/validators.js b/test/validators.js index e2ecf9959..95c17ef80 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8259,6 +8259,27 @@ describe('Validators', () => { '3001234567', ], }, + { + locale: ['tg-TJ'], + valid: [ + '+992553388551', + '+992553322551', + '992553388551', + '992553322551', + ], + invalid: [ + '12345', + '', + 'Vml2YW11cyBmZXJtZtesting123', + '+995563388559', + '+9955633559', + '19676338855', + '+992263388505', + '9923633885', + '99255363885', + '66338855', + ], + }, ]; let allValid = []; From fc0fefc08272dae2b824fdc8b17fe27476b28e3d Mon Sep 17 00:00:00 2001 From: lakshayr003 <91641983+lakshayr003@users.noreply.github.com> Date: Sun, 31 Oct 2021 14:28:51 +0530 Subject: [PATCH 100/113] feat(isMobilePhone): add Bhutan dz-BT locale (#1770) * Add dz-BT to isMobilePhone.js * Add isMobilePhone test for dz-BT * Added isMobilePhone regex for dz-BT Added mobile operator codes as well * Added dz-BT in isMobilePhone readme * Added isMobilePhone test for dz-BT Updated the test cases --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 473f04aec..d074f8dab 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-BM', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', '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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-BM', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW', 'dz-BT']` 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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index b9d14f635..9f24bb916 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -121,6 +121,7 @@ const phones = { 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, + 'dz-BT': /^(\+?975|0)?(17|16|77|02)\d{6}$/, }; /* eslint-enable max-len */ diff --git a/test/validators.js b/test/validators.js index 95c17ef80..9faf73d56 100644 --- a/test/validators.js +++ b/test/validators.js @@ -5991,6 +5991,23 @@ describe('Validators', () => { '00212408186135', ], }, + { + locale: 'dz-BT', + valid: [ + '+97517374354', + '+97517454971', + '77324646', + '016329712', + '97517265559', + ], + invalid: [ + '', + '9898347255', + '+96326626262', + '963372', + '0114152198', + ], + }, { locale: 'ar-OM', valid: [ From 5c2d69e4699693f10d53e74c8958b2fbe3af0a64 Mon Sep 17 00:00:00 2001 From: ZeeMangena Date: Sat, 23 Oct 2021 21:53:46 +0200 Subject: [PATCH 101/113] feat(isMobilePhone): regex for Burkina Faso fr-BF and Namibia en-NA locales chore: squashed commits from #1834 feat(isMobilePhone): regex for Namibia locale fix(isMobilePhone): removing telephone validation fix(isMobliePhone): regex now validates as intended fix(isMobilePhone): requiring phone number prefixes in validation feat(isMobilePhone): regex for Burkina Faso locale fix(isMobilePhone): removing code intended for a different branch fix(isMobilePhone): Making plus sign optional feat(isMobilePhone): regex for Burkina Faso locale --- src/lib/isMobilePhone.js | 2 ++ test/validators.js | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 9f24bb916..6d5a3eb13 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -42,6 +42,7 @@ const phones = { 'en-KE': /^(\+?254|0)(7|1)\d{8}$/, 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/, 'en-MU': /^(\+?230|0)?\d{8}$/, + 'en-NA': /^(\+?264|0)(6|8)\d{7}$/, 'en-NG': /^(\+?234|0)?[789]\d{9}$/, 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/, 'en-PK': /^((00|\+)?92|0)3[0-6]\d{8}$/, @@ -76,6 +77,7 @@ const phones = { 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/, 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, + 'fr-BF': /^(\+226|0)[67]\d{7}$/, 'fr-CM': /^(\+?237)6[0-9]{8}$/, 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, diff --git a/test/validators.js b/test/validators.js index 9faf73d56..18583a07e 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6733,6 +6733,31 @@ describe('Validators', () => { '+3361245789', ], }, + { + locale: 'fr-BF', + valid: [ + '+22661245789', + '+22665903092', + '+22672457898', + '+22673572346', + '061245789', + '071245783', + ], + invalid: [ + '0612457892', + '06124578980', + '0112457898', + '0212457898', + '0312457898', + '0412457898', + '0512457898', + '0812457898', + '0912457898', + '+22762457898', + '+226724578980', + '+22634523', + ], + }, { locale: 'fr-CA', valid: ['19876543210', '8005552222', '+15673628910'], @@ -7000,6 +7025,27 @@ describe('Validators', () => { '66338855', ], }, + { + locale: ['en-NA'], + valid: [ + '+26466189012', + '+26461555804', + '+26461434221', + '+26487555169', + '+26481555663', + ], + invalid: [ + '12345', + '', + 'Vml2YW11cyBmZXJtZtesting123', + '+2641234567890', + '+2641234567', + '+2648143422', + '+264981234', + '4736338855', + '66338855', + ], + }, { locale: 'ru-RU', valid: [ From c96d8059857af2e51a943197bd16b3e88e7efdcc Mon Sep 17 00:00:00 2001 From: Prajwal Raj Basnet Date: Tue, 26 Oct 2021 00:32:37 +0545 Subject: [PATCH 102/113] feat(isMobilePhone): add Maldives dv-MV locale chore: squashed #1829 Add locale for Maldives in mobile phone validator Add tests for mobile numbers validation of maldives locale i.e. dv-MV Update readme to add Maldives locale (dv-MV) in isMobilePhone documentation --- src/lib/isMobilePhone.js | 1 + test/validators.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 6d5a3eb13..d60b3ce8b 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -29,6 +29,7 @@ const phones = { 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/, 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/, 'de-LU': /^(\+352)?((6\d1)\d{6})$/, + 'dv-MV': /^(\+?960)?(7[2-9]|91|9[3-9])\d{7}$/, 'el-GR': /^(\+?30|0)?(69\d{8})$/, 'en-AU': /^(\+?61|0)4\d{8}$/, 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}))/, diff --git a/test/validators.js b/test/validators.js index 18583a07e..74289e072 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8343,6 +8343,23 @@ describe('Validators', () => { '66338855', ], }, + { + locale: 'dv-MV', + valid: [ + '+960973256874', + '781246378', + '+960766354789', + '+960912354789', + ], + invalid: [ + '+96059234567', + '+96045789', + '7812463784', + '+960706985478', + '+960926985478', + 'NotANumber', + ], + }, ]; let allValid = []; From ed601236d64fb00934ac9bbb1dc5102f8281dc20 Mon Sep 17 00:00:00 2001 From: Magnus Sustad <56775490+mgnss@users.noreply.github.com> Date: Sun, 31 Oct 2021 06:17:25 +0100 Subject: [PATCH 103/113] feat(isMobilePhone): add Tajikistan tg-TJ locale (#1846) --- test/validators.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/validators.js b/test/validators.js index 74289e072..df733845a 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8360,6 +8360,27 @@ describe('Validators', () => { 'NotANumber', ], }, + { + locale: ['tg-TJ'], + valid: [ + '+992553388551', + '+992553322551', + '992553388551', + '992553322551', + ], + invalid: [ + '12345', + '', + 'Vml2YW11cyBmZXJtZtesting123', + '+995563388559', + '+9955633559', + '19676338855', + '+992263388505', + '9923633885', + '99255363885', + '66338855', + ], + }, ]; let allValid = []; From 8627e4815bcbbab7474ce23ae1c2599b3dba5462 Mon Sep 17 00:00:00 2001 From: Chris Tanner Date: Fri, 22 Oct 2021 13:45:03 -0400 Subject: [PATCH 104/113] feat(isMobilePhone): add Kiribati en-KI locale [chore] squashed from #1820 Clean up validator and add trailing comma --- src/lib/isMobilePhone.js | 1 + test/validators.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index d60b3ce8b..70b032cf8 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -41,6 +41,7 @@ const phones = { 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, 'en-IN': /^(\+?91|0)?[6789]\d{9}$/, 'en-KE': /^(\+?254|0)(7|1)\d{8}$/, + 'en-KI': /^((\+686|686)?)?( )?((6|7)(2|3|8)[0-9]{6})$/, 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/, 'en-MU': /^(\+?230|0)?\d{8}$/, 'en-NA': /^(\+?264|0)(6|8)\d{7}$/, diff --git a/test/validators.js b/test/validators.js index df733845a..e3c69f0a0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6608,6 +6608,22 @@ describe('Validators', () => { '+254800723845', ], }, + { + locale: 'en-KI', + valid: [ + '+68673140000', + '68673059999', + '+68663000000', + '68663019999', + ], + invalid: [ + '+68653000000', + '68664019999', + '+68619019999', + '686123456789', + '+686733445', + ], + }, { locale: 'en-MT', valid: [ From f7ff349b0c0429a2c41cc18bc86fc85e9224ab4d Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Sat, 16 Oct 2021 11:35:42 -0500 Subject: [PATCH 105/113] feat(isMobilePhone): add Frech Polynesia fr-PF locale Create validation for frech polynesia mobile phones according to wikipedia: https://en.wikipedia.org/wiki/Telephone_numbers_in_French_Polynesia#Mobile --- src/lib/isMobilePhone.js | 1 + test/validators.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 70b032cf8..404d9b02c 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -85,6 +85,7 @@ const phones = { 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/, + 'fr-PF': /^(\+?689)?8[789]\d{6}$/, 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/, 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/, 'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/, diff --git a/test/validators.js b/test/validators.js index e3c69f0a0..8b12c03df 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6885,6 +6885,28 @@ describe('Validators', () => { '+26261245789', ], }, + { + locale: 'fr-PF', + valid: [ + '87123456', + '88123456', + '89123456', + '+68987123456', + '+68988123456', + '+68989123456', + '68987123456', + '68988123456', + '68989123456', + ], + invalid: [ + '7123456', + '86123456', + '87 12 34 56', + 'definitely not a number', + '01+68988123456', + '6898912345', + ], + }, { locale: 'ka-GE', valid: [ From 0e5d5d4216885a4aa03a88c3c462e8a96110c378 Mon Sep 17 00:00:00 2001 From: Maximilian Krause Date: Tue, 12 Oct 2021 23:18:02 +0200 Subject: [PATCH 106/113] feat(isMobilePhone): add Guyana en-GY locale [chore] fixed merge conflicts in #1784 feat: (isMobilePhone) Add Guyana mobile phone validation Fix linter errors --- src/lib/isMobilePhone.js | 1 + test/validators.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 404d9b02c..690075838 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -36,6 +36,7 @@ const phones = { 'en-GB': /^(\+?44|0)7\d{9}$/, 'en-GG': /^(\+?44|0)1481\d{6}$/, 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28|55|59)\d{7}$/, + 'en-GY': /^(\+592|0)6\d{6}$/, 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/, 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/, 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 8b12c03df..76de75bd5 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6523,6 +6523,22 @@ describe('Validators', () => { '+233292345671', ], }, + { + locale: 'en-GY', + valid: [ + '+5926121234', + '06121234', + '06726381', + '+5926726381', + ], + invalid: [ + '5926121234', + '6121234', + '+592 6121234', + '05926121234', + '+592-6121234', + ], + }, { locale: 'en-HK', valid: [ From 26605f9881495a0b6774dcd51833f566c0d6b794 Mon Sep 17 00:00:00 2001 From: Husan Eshonqulov <75156942+Husan-Eshonqulov@users.noreply.github.com> Date: Tue, 12 Oct 2021 22:41:24 +0500 Subject: [PATCH 107/113] feat(isMobilePhone): add Turkmenistan tk-TM squashed commits and resolved merge conflict for #1780 Add Turkmenistan validation regax Update README.md to include Turkmenistan (tk-Tm) Add test cases for tk-TM add missing comma for isMobilePhone.js add missing commas for test/validators.js --- src/lib/isMobilePhone.js | 1 + test/validators.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 690075838..2e599de5a 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -122,6 +122,7 @@ const phones = { 'tg-TJ': /^(\+?992)?[5][5]\d{7}$/, 'th-TH': /^(\+66|66|0)\d{9}$/, 'tr-TR': /^(\+?90|0)?5\d{9}$/, + 'tk-TM': /^(\+993|993|8)\d{8}$/, 'uk-UA': /^(\+?38|8)?0\d{9}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, diff --git a/test/validators.js b/test/validators.js index 76de75bd5..9be3c840c 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8201,6 +8201,22 @@ describe('Validators', () => { '081234567891', ], }, + { + locale: 'tk-TM', + valid: [ + '+99312495154', + '99312130136', + '+99312918407', + '99312183399', + '812391717', + ], + invalid: [ + '12345', + '+99412495154', + '99412495154', + '998900066506', + ], + }, { locale: ['en-ZA', 'be-BY'], valid: [ From a3faa8392783aed01d709e4e786ad35e32f743ef Mon Sep 17 00:00:00 2001 From: Megan Date: Sun, 10 Oct 2021 13:47:04 -0500 Subject: [PATCH 108/113] feat(isMobilePhone): add Botswana en-BW locale Added new condition for Botswana New regex for Botswana numbers Phone number information was found from the following sources: - https://www.howtocallabroad.com/botswana/ - https://countrycode.org/botswana Updated README.md to include en-BW Included the new case for Botswana (en-BW) Added test cases for isMobilePhone en-BW Added some test cases to check length for the phone number & area code pattern. Changed regex for BW Fixed the pattern for Botswana mobile phone numbers and edited the test cases. I followed the convention from Table 8 of the national numbering plan document and the mobile number pattern on the Wiki page. Update validators.js Oops! Looks like the file didn't update with some of my modified test cases - my apologies! --- src/lib/isMobilePhone.js | 1 + test/validators.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 2e599de5a..ef5584934 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -59,6 +59,7 @@ const phones = { 'en-ZA': /^(\+?27|0)\d{9}$/, 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'en-ZW': /^(\+263)[0-9]{9}$/, + 'en-BW': /^(\+?267)?(7[1-8]{1})\d{6}$/, 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/, 'es-BO': /^(\+?591)?(6|7)\d{7}$/, 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 9be3c840c..da36a29b1 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8261,6 +8261,31 @@ describe('Validators', () => { '23274560591 ', ], }, + { + locale: 'en-BW', + valid: [ + '+26772868545', + '+26776368790', + '+26774560512', + '26774560591', + '26778560512', + '74560512', + '76710284', + ], + invalid: [ + '0799375902', + '12345', + '+2670745605448', + '2670745605482', + '+26779685451', + '+26770685451', + '267074560', + '2670ab5608', + '+267074560', + '70560512', + '79710284', + ], + }, { locale: 'az-AZ', valid: [ From 5b067037996768f032facd5f2aeb89bb20188aa3 Mon Sep 17 00:00:00 2001 From: Brendan C <30474072+brendan-c@users.noreply.github.com> Date: Sat, 9 Oct 2021 18:12:16 -0400 Subject: [PATCH 109/113] feat(isMobilePhone): add Palestine ar-PS locale Add isMobilePhone test for ar-PS Add ar-PS to isMobilePhone readme Correct ar-PS validation Update ar-PS isMobible tests --- src/lib/isMobilePhone.js | 1 + test/validators.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index ef5584934..f5a8ffa6b 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -14,6 +14,7 @@ const phones = { 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/, 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/, 'ar-OM': /^((\+|00)968)?(9[1-9])\d{6}$/, + 'ar-PS': /^(\+?970|0)5[6|9](\d{7})$/, 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/, 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, 'ar-TN': /^(\+?216)?[2459]\d{7}$/, diff --git a/test/validators.js b/test/validators.js index da36a29b1..32bb79974 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6027,6 +6027,26 @@ describe('Validators', () => { '02122333', ], }, + { + locale: 'ar-PS', + valid: [ + '+970563459876', + '970592334218', + '0566372345', + '0598273583', + ], + invalid: [ + '+9759029487', + '97059123456789', + '598372348', + '97058aaaafjd', + '', + '05609123484', + '+97059', + '+970', + '97056', + ], + }, { locale: 'ar-SY', valid: [ From f17e220b1d8788549d5f9cb80662d001bad7fdbf Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Sat, 9 Oct 2021 15:03:28 -0500 Subject: [PATCH 110/113] feat(isMobilePhone): add El Salvador es-SV locale * Solve issue with wrong validation on El Salvador mobile phones * update tests accordingly in order to define the right regEx, the following site was consulted. https://www.siget.gob.sv/guia-de-servicios/consulta-el-plan-de-numeracion/numeros-moviles/ --- src/lib/isMobilePhone.js | 1 + test/validators.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index f5a8ffa6b..c70310ef7 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -75,6 +75,7 @@ const phones = { 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/, 'es-PA': /^(\+?507)\d{7,8}$/, 'es-PY': /^(\+?595|0)9[9876]\d{7}$/, + 'es-SV': /^(\+?503)?[67]\d{7}$/, 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/, 'es-VE': /^(\+?58)?(2|4)\d{9}$/, 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/, diff --git a/test/validators.js b/test/validators.js index 32bb79974..14e3bfc93 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7576,6 +7576,30 @@ describe('Validators', () => { '+591993546843', ], }, + { + locale: 'es-SV', + valid: [ + '62136634', + '50361366631', + '+50361366634', + '+50361367217', + '+50361367460', + '+50371367632', + '+50371367767', + '+50371368314', + ], + invalid: [ + '+5032136663', + '21346663', + '+50321366663', + '12345', + 'El salvador', + 'this should fail', + '+5032222', + '+503 1111 1111', + '00 +503 1234 5678', + ], + }, { locale: 'es-UY', valid: [ From 83cb7f8cca9e62c26852bc28ba600680751a36f1 Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Sun, 31 Oct 2021 15:00:36 +0300 Subject: [PATCH 111/113] chore: merge conflict clean-up --- README.md | 2 +- test/validators.js | 21 --------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/README.md b/README.md index d074f8dab..2cf6505be 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-BM', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW', 'dz-BT']` 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`. +**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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'dv-MV', 'el-GR', 'en-AU', 'en-BM', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-KI', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW', 'dz-BT']` 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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`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', 'fr-CA', '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']`. diff --git a/test/validators.js b/test/validators.js index 14e3bfc93..a4e00293b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8499,27 +8499,6 @@ describe('Validators', () => { 'NotANumber', ], }, - { - locale: ['tg-TJ'], - valid: [ - '+992553388551', - '+992553322551', - '992553388551', - '992553322551', - ], - invalid: [ - '12345', - '', - 'Vml2YW11cyBmZXJtZtesting123', - '+995563388559', - '+9955633559', - '19676338855', - '+992263388505', - '9923633885', - '99255363885', - '66338855', - ], - }, ]; let allValid = []; From 496fc8b2a7f5997acaaec33cc44d0b8dba5fb5e1 Mon Sep 17 00:00:00 2001 From: Sarhan Aissi Date: Mon, 1 Nov 2021 21:30:39 +0100 Subject: [PATCH 112/113] fix(rtrim): remove regex to prevent ReDOS attack (#1738) --- src/lib/rtrim.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/rtrim.js b/src/lib/rtrim.js index d10aaa9de..2d311574b 100644 --- a/src/lib/rtrim.js +++ b/src/lib/rtrim.js @@ -2,7 +2,16 @@ import assertString from './util/assertString'; export default function rtrim(str, chars) { assertString(str); - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping - const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /(\s)+$/g; - return str.replace(pattern, ''); + if (chars) { + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping + const pattern = new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g'); + return str.replace(pattern, ''); + } + // Use a faster and more safe than regex trim method https://blog.stevenlevithan.com/archives/faster-trim-javascript + let strIndex = str.length - 1; + while (/\s/.test(str.charAt(strIndex))) { + strIndex -= 1; + } + + return str.slice(0, strIndex + 1); } From 47ee5ad64cf5c684c841b59110af4e221b74945c Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Tue, 2 Nov 2021 00:02:10 +0300 Subject: [PATCH 113/113] 13.7.0 --- CHANGELOG.md | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- src/index.js | 2 +- 3 files changed, 91 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aec8e38fb..6b063ff2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,92 @@ +## 13.7.0 + +### New Features + +- [#1706](https://github.com/validatorjs/validator.js/pull/1706) `isISO4217`, currency code validator @jpaya17 + +### New Features + +- [#1706](https://github.com/validatorjs/validator.js/pull/1706) `isISO4217`, currency code validator @jpaya17 + +### Fixes and Enhancements + +- [#1647](https://github.com/validatorjs/validator.js/pull/1647) `isFQDN`: add `allow_wildcard` option @fasenderos +- [#1654](https://github.com/validatorjs/validator.js/pull/1654) `isRFC3339`: Disallow prepended and appended strings to RFC 3339 date-time @jmacmahon +- [#1658](https://github.com/validatorjs/validator.js/pull/1658) maintenance: increase code coverage @tux-tn +- [#1669](https://github.com/validatorjs/validator.js/pull/1669) `IBAN` export list of country codes that implement IBAN @dror-heller @fedeci +- [#1676](https://github.com/validatorjs/validator.js/pull/1676) `isBoolean`: add `loose` option @brybrophy +- [#1697](https://github.com/validatorjs/validator.js/pull/1697) maintenance: fix npm installation error @rubiin +- [#1708](https://github.com/validatorjs/validator.js/pull/1708) `isISO31661Alpha3`: perf @jpaya17 +- [#1711](https://github.com/validatorjs/validator.js/pull/1711) `isDate`: allow users to strictly validate dates with `.` as delimiter @flymans +- [#1715](https://github.com/validatorjs/validator.js/pull/1715) `isCreditCard`: fix for Union Pay cards @shreyassai123 +- [#1718](https://github.com/validatorjs/validator.js/pull/1718) `isEmail`: replace all dots in GMail length validation @DasDingGehtNicht +- [#1721](https://github.com/validatorjs/validator.js/pull/1721) `isURL`: add `allow_fragments` and `allow_query_components` @cowboy-bebug +- [#1724](https://github.com/validatorjs/validator.js/pull/1724) `isISO31661Alpha2`: perf @jpaya17 +- [#1730](https://github.com/validatorjs/validator.js/pull/1730) `isMagnetURI` @tux-tn +- [#1738](https://github.com/validatorjs/validator.js/pull/1738) `rtrim`: remove regex to prevent ReDOS attack @tux-tn +- [#1747](https://github.com/validatorjs/validator.js/pull/1747) maintenance: run scripts in parallel for build and clean @sachinraja +- [#1748](https://github.com/validatorjs/validator.js/pull/1748) `isURL`: higher priority to `whitelist` @deepanshu2506 +- [#1751](https://github.com/validatorjs/validator.js/pull/1751) `isURL`: allow url with colon and no port @MatteoPierro +- [#1777](https://github.com/validatorjs/validator.js/pull/1777) `isUUID`: fix for `null` version argument @theteladras +- [#1799](https://github.com/validatorjs/validator.js/pull/1799) `isFQDN`: check more special chars @MatteoPierro +- [#1833](https://github.com/validatorjs/validator.js/pull/1833) `isURL`: allow URL with an empty user @MiguelSavignano +- [#1835](https://github.com/validatorjs/validator.js/pull/1835) `unescape`: fixed bug where intermediate string contains escaped @Marcholio +- [#1836](https://github.com/validatorjs/validator.js/pull/1836) `contains`: can check that string contains seed multiple times @Marcholio +- [#1844](https://github.com/validatorjs/validator.js/pull/1844) docs: add CDN instructions @luiscobits +- [#1848](https://github.com/validatorjs/validator.js/pull/1848) `isUUID`: add support for validation of `v1` and `v2` @theteladras +- [#1941](https://github.com/validatorjs/validator.js/pull/1641) `isEmail`: add `host_blacklist` option @fedeci + +### New and Improved Locales + +- `isAlpha`, `isAlphanumeric`: + - [#1716](https://github.com/validatorjs/validator.js/pull/1716) `hi-IN` @MiKr13 + - [#1837](https://github.com/validatorjs/validator.js/pull/1837) `fi-FI` @Marcholio + +- `isPassportNumber`: + - [#1656](https://github.com/validatorjs/validator.js/pull/1656) `ID` @rubiin + - [#1714](https://github.com/validatorjs/validator.js/pull/1714) `CN` @anirudhgiri + - [#1809](https://github.com/validatorjs/validator.js/pull/1809) `PL` @Ronqn + - [#1810](https://github.com/validatorjs/validator.js/pull/1810) `RU` @Theta-Dev + +- `isPostalCode`: + - [#1788](https://github.com/validatorjs/validator.js/pull/1788) `LK` @nimanthadilz + +- `isIdentityCard`: + - [#1657](https://github.com/validatorjs/validator.js/pull/1657) `TH` @tithanayut + - [#1745](https://github.com/validatorjs/validator.js/pull/1745) `PL` @wiktorwojcik112 @fedeci @tux-tn + - [#1786](https://github.com/validatorjs/validator.js/pull/1786) `LK` @nimanthadilz @tux-tn + - [#1838](https://github.com/validatorjs/validator.js/pull/1838) `FI` @Marcholio + +- `isMobilePhone`: + - [#1679](https://github.com/validatorjs/validator.js/pull/1679) `de-DE` @AnnaMariaJansen + - [#1689](https://github.com/validatorjs/validator.js/pull/1689) `vi-VN` @luisrivas + - [#1695](https://github.com/validatorjs/validator.js/pull/1695) [#1682](https://github.com/validatorjs/validator.js/pull/1682) `zh-CN` @laulujan @yisibl + - [#1734](https://github.com/validatorjs/validator.js/pull/1734) `es-VE` @islasjuanp + - [#1746](https://github.com/validatorjs/validator.js/pull/1746) `nl-BE` @divikshrivastava + - [#1765](https://github.com/validatorjs/validator.js/pull/1765) `es-CU` @pasagedev + - [#1766](https://github.com/validatorjs/validator.js/pull/1766) `es-SV`, @hereje + - [#1767](https://github.com/validatorjs/validator.js/pull/1767) `ar-PS`, @brendan-c + - [#1769](https://github.com/validatorjs/validator.js/pull/1769) `en-BM` @HackProAIT + - [#1770](https://github.com/validatorjs/validator.js/pull/1770) `dz-BT` @lakshayr003 + - [#1771](https://github.com/validatorjs/validator.js/pull/1771) `en-BW`, @mgndolan + - [#1772](https://github.com/validatorjs/validator.js/pull/1772) `fr-CM` @beckettnormington + - [#1778](https://github.com/validatorjs/validator.js/pull/1778) `en-PK` @ammad20120 @tux-tn + - [#1780](https://github.com/validatorjs/validator.js/pull/1780) `tk-TM`, @Husan-Eshonqulov + - [#1784](https://github.com/validatorjs/validator.js/pull/1784) `en-GY`, @mfkrause + - [#1785](https://github.com/validatorjs/validator.js/pull/1785) `si-LK` @Madhavi96 + - [#1797](https://github.com/validatorjs/validator.js/pull/1797) `fr-PF`, @hereje + - [#1820](https://github.com/validatorjs/validator.js/pull/1820) `en-KI`, @c-tanner + - [#1826](https://github.com/validatorjs/validator.js/pull/1826) `hu-HU` @danielTiringer + - [#1834](https://github.com/validatorjs/validator.js/pull/1834) `fr-BF`, `en-NA` @lakshayr003 + - [#1846](https://github.com/validatorjs/validator.js/pull/1846) `tg-TJ` @mgnss + +- `isLicensePlate`: + - [#1565](https://github.com/validatorjs/validator.js/pull/1565) `cs-CZ` @filiptronicek + - [#1790](https://github.com/validatorjs/validator.js/pull/1790) `fi-FI` @Marcholio + +- `isVAT`: + - [#1825](https://github.com/validatorjs/validator.js/pull/1825) `NL` @zeno4ever + #### 13.6.1 - **New features**: diff --git a/package.json b/package.json index a912c032a..7d505205e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "validator", "description": "String validation and sanitization", - "version": "13.6.0", + "version": "13.7.0", "sideEffects": false, "homepage": "https://github.com/validatorjs/validator.js", "files": [ diff --git a/src/index.js b/src/index.js index a0e8aa63c..b8ad651ee 100644 --- a/src/index.js +++ b/src/index.js @@ -121,7 +121,7 @@ import isStrongPassword from './lib/isStrongPassword'; import isVAT from './lib/isVAT'; -const version = '13.6.0'; +const version = '13.7.0'; const validator = { version,