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
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/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/README.md b/README.md
index 7dbed1295..2cf6505be 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)
@@ -82,18 +88,18 @@ 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', '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', '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.
**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.
@@ -103,11 +109,11 @@ 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`.
-**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']`
@@ -115,7 +121,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 `['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).
@@ -126,27 +132,28 @@ 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.
**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', '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'.
**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-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']`.
**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', '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', '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).
@@ -155,10 +162,10 @@ 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).
-**isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5).
+**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 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' ]`.
+**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/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..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": [
@@ -46,9 +46,10 @@
"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.43.0",
+ "rollup": "^0.47.0",
"rollup-plugin-babel": "^4.0.1",
"uglify-js": "^3.0.19"
},
@@ -58,15 +59,14 @@
"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 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/index.js b/src/index.js
index 675947481..b8ad651ee 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';
@@ -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';
@@ -120,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,
@@ -198,6 +199,7 @@ const validator = {
isRFC3339,
isISO31661Alpha2,
isISO31661Alpha3,
+ isISO4217,
isBase32,
isBase58,
isBase64,
@@ -222,6 +224,7 @@ const validator = {
isDate,
isLicensePlate,
isVAT,
+ ibanLocales,
};
export default validator;
diff --git a/src/lib/alpha.js b/src/lib/alpha.js
index c898cacfe..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,
@@ -30,6 +31,7 @@ export const alpha = {
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[א-ת]+$/,
fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
+ 'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i,
};
export const alphanumeric = {
@@ -41,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,
@@ -63,6 +66,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 +111,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/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/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/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/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/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/src/lib/isEmail.js b/src/lib/isEmail.js
index ecbd398c9..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.
@@ -110,7 +115,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/src/lib/isFQDN.js b/src/lib/isFQDN.js
index 3dff7d2fd..4a04cf34e 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];
@@ -25,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/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/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;
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());
}
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/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js
index 872ff1920..9dc1302ad 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);
@@ -30,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}$/;
@@ -117,6 +170,24 @@ 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();
+ },
+ 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/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js
index a28d66da8..d6b27a5ad 100644
--- a/src/lib/isLicensePlate.js
+++ b/src/lib/isLicensePlate.js
@@ -1,9 +1,12 @@
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),
+ '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/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/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js
index 95b568547..c70310ef7 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}$/,
@@ -25,25 +26,30 @@ 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})$/,
+ '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}))/,
'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}$/,
'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}$/,
'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}$/,
@@ -54,11 +60,13 @@ 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}$/,
'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}$/,
@@ -67,19 +75,24 @@ 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}$/,
'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-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}$/,
'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)(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}$/,
@@ -94,7 +107,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}$/,
@@ -103,19 +116,22 @@ 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}$/,
'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}$/,
+ '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([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}$/,
+ '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/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js
index 51a8e70ac..4c38bfbbe 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
@@ -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
@@ -46,10 +47,10 @@ 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
+ 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/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/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/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/src/lib/isURL.js b/src/lib/isURL.js
index 4306e5deb..aa6222a90 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('#');
@@ -101,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('@');
@@ -126,7 +140,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;
@@ -135,15 +149,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;
}
diff --git a/src/lib/isUUID.js b/src/lib/isUUID.js
index 61d938ac3..c026ca78c 100644
--- a/src/lib/isUUID.js
+++ b/src/lib/isUUID.js
@@ -1,14 +1,16 @@
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,
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];
- return pattern && pattern.test(str);
+ const pattern = uuid[![undefined, null].includes(version) ? version : 'all'];
+ return !!pattern && pattern.test(str);
}
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/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);
}
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/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);
+ });
});
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: <':
+ 'Escaped string: <',
},
});
});
diff --git a/test/validators.js b/test/validators.js
index 31b7f960e..a4e00293b 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',
@@ -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',
@@ -350,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/',
@@ -521,6 +536,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',
@@ -541,6 +581,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',
@@ -1024,6 +1100,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',
@@ -1068,6 +1156,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({
@@ -1397,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',
@@ -1627,6 +1745,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',
@@ -1862,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',
@@ -1985,6 +2140,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',
@@ -2345,6 +2520,22 @@ describe('Validators', () => {
],
});
+
+ test({
+ validator: 'isPassportNumber',
+ args: ['ID'],
+ valid: [
+ 'C1253473',
+ 'B5948378',
+ 'A4859472',
+ ],
+ invalid: [
+ 'D39481728',
+ 'A-3847362',
+ '324132132',
+ ],
+ });
+
test({
validator: 'isPassportNumber',
args: ['AR'],
@@ -2459,9 +2650,15 @@ describe('Validators', () => {
valid: [
'G25352389',
'E00160027',
+ 'EA1234567',
],
invalid: [
'K0123456',
+ 'E-1234567',
+ 'G.1234567',
+ 'GA1234567',
+ 'EI1234567',
+ 'GO1234567',
],
});
@@ -2840,7 +3037,7 @@ describe('Validators', () => {
test({
validator: 'isPassportNumber',
- args: ['PO'],
+ args: ['PL'],
valid: [
'ZS 0000177',
'AN 3000011',
@@ -2881,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',
],
});
@@ -4128,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', () => {
@@ -4302,6 +4510,63 @@ 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: [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],
@@ -4353,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', () => {
@@ -4553,6 +4830,8 @@ describe('Validators', () => {
'2718760626256570',
'6765780016990268',
'4716989580001715211',
+ '8171999927660000',
+ '8171999900000000021',
],
invalid: [
'foo',
@@ -4573,6 +4852,52 @@ 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: [
+ '99012229019',
+ '09210215408',
+ '20313034701',
+ '86051575214',
+ '77334586883',
+ '54007481320',
+ '06566860643',
+ '77552478861',
+ ],
+ invalid: [
+ 'aa',
+ '5',
+ '195',
+ '',
+ ' ',
+ '12345678901',
+ '99212229019',
+ '09210215402',
+ '20313534701',
+ '86241579214',
+ ],
+ },
{
locale: 'ES',
valid: [
@@ -4601,6 +4926,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: [
@@ -4674,6 +5013,24 @@ describe('Validators', () => {
'92031470790',
],
},
+ {
+ locale: 'TH',
+ valid: [
+ '1101230000001',
+ '1101230000060',
+ ],
+ invalid: [
+ 'abc',
+ '1101230',
+ '11012300000011',
+ 'aaaaaaaaaaaaa',
+ '110123abcd001',
+ '1101230000007',
+ '0101123450000',
+ '0101123450004',
+ '9101123450008',
+ ],
+ },
{
locale: 'he-IL',
valid: [
@@ -5634,6 +5991,23 @@ describe('Validators', () => {
'00212408186135',
],
},
+ {
+ locale: 'dz-BT',
+ valid: [
+ '+97517374354',
+ '+97517454971',
+ '77324646',
+ '016329712',
+ '97517265559',
+ ],
+ invalid: [
+ '',
+ '9898347255',
+ '+96326626262',
+ '963372',
+ '0114152198',
+ ],
+ },
{
locale: 'ar-OM',
valid: [
@@ -5653,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: [
@@ -5812,21 +6206,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',
@@ -5836,6 +6229,7 @@ describe('Validators', () => {
'16412345678',
'17012345678',
'+4912345678910',
+ '+49015123456789',
],
},
{
@@ -5855,6 +6249,19 @@ describe('Validators', () => {
'064349089895623459',
],
},
+ {
+ locale: 'hu-HU',
+ valid: [
+ '06301234567',
+ '+36201234567',
+ '06701234567',
+ ],
+ invalid: [
+ '1234',
+ '06211234567',
+ '+3620123456',
+ ],
+ },
{
locale: 'mz-MZ',
valid: [
@@ -5946,19 +6353,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',
@@ -5967,14 +6383,25 @@ describe('Validators', () => {
'+8619312341234',
'+8619212341234',
'+8619112341234',
- '17269427292',
- '16565600001',
'+8617269427292',
+ '008618812341234',
+ '008618812341234',
'008617269427292',
+ // Reserve number segments in the future.
+ '92138389438',
+ '+8692138389438',
+ '008692138389438',
+ '98199649964',
+ '+8698099649964',
+ '008698099649964',
],
invalid: [
'12345',
'',
+ '12038389438',
+ '12838389438',
+ '013838389438',
+ '+86-13838389438',
'+08613811211114',
'+008613811211114',
'08613811211114',
@@ -6000,6 +6427,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: [
@@ -6096,6 +6543,22 @@ describe('Validators', () => {
'+233292345671',
],
},
+ {
+ locale: 'en-GY',
+ valid: [
+ '+5926121234',
+ '06121234',
+ '06726381',
+ '+5926726381',
+ ],
+ invalid: [
+ '5926121234',
+ '6121234',
+ '+592 6121234',
+ '05926121234',
+ '+592-6121234',
+ ],
+ },
{
locale: 'en-HK',
valid: [
@@ -6181,6 +6644,22 @@ describe('Validators', () => {
'+254800723845',
],
},
+ {
+ locale: 'en-KI',
+ valid: [
+ '+68673140000',
+ '68673059999',
+ '+68663000000',
+ '68663019999',
+ ],
+ invalid: [
+ '+68653000000',
+ '68664019999',
+ '+68619019999',
+ '686123456789',
+ '+686733445',
+ ],
+ },
{
locale: 'en-MT',
valid: [
@@ -6306,6 +6785,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'],
@@ -6417,6 +6921,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: [
@@ -6573,6 +7099,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: [
@@ -6600,14 +7147,13 @@ describe('Validators', () => {
'0786642116',
'078 7642116',
'078-7642116',
-
+ '0749994567',
],
invalid: [
'9912349956789',
'12345',
'1678123456',
'0731234567',
- '0749994567',
'0797878674',
],
},
@@ -6729,6 +7275,8 @@ describe('Validators', () => {
'0892405867',
'+84888696413',
'0878123456',
+ '84781234567',
+ '0553803765',
],
invalid: [
'12345',
@@ -6740,6 +7288,8 @@ describe('Validators', () => {
'+841698765432',
'841626543219',
'0533803765',
+ '08712345678',
+ '+0321234567',
],
},
{
@@ -6853,6 +7403,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: [
@@ -6998,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: [
@@ -7015,6 +7617,19 @@ describe('Validators', () => {
'099 999 999',
],
},
+ {
+ locale: 'es-VE',
+ valid: [
+ '+582125457765',
+ '+582125458053',
+ '+584125458053',
+ ],
+ invalid: [
+ '+585129934395',
+ '+58212993439',
+ '',
+ ],
+ },
{
locale: 'et-EE',
valid: [
@@ -7164,6 +7779,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: [
@@ -7252,9 +7882,9 @@ describe('Validators', () => {
'0470123456',
'+32470123456',
'32470123456',
- '021234567',
- '+3221234567',
- '3221234567',
+ '0421234567',
+ '+32421234567',
+ '32421234567',
],
invalid: [
'12345',
@@ -7266,6 +7896,9 @@ describe('Validators', () => {
'0212345678',
'+320212345678',
'320212345678',
+ '021234567',
+ '+3221234567',
+ '3221234567',
],
},
{
@@ -7274,9 +7907,9 @@ describe('Validators', () => {
'0470123456',
'+32470123456',
'32470123456',
- '021234567',
- '+3221234567',
- '3221234567',
+ '0421234567',
+ '+32421234567',
+ '32421234567',
],
invalid: [
'12345',
@@ -7288,6 +7921,9 @@ describe('Validators', () => {
'0212345678',
'+320212345678',
'320212345678',
+ '021234567',
+ '+3221234567',
+ '3221234567',
],
},
{
@@ -7609,6 +8245,22 @@ describe('Validators', () => {
'081234567891',
],
},
+ {
+ locale: 'tk-TM',
+ valid: [
+ '+99312495154',
+ '99312130136',
+ '+99312918407',
+ '99312183399',
+ '812391717',
+ ],
+ invalid: [
+ '12345',
+ '+99412495154',
+ '99412495154',
+ '998900066506',
+ ],
+ },
{
locale: ['en-ZA', 'be-BY'],
valid: [
@@ -7653,6 +8305,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: [
@@ -7764,6 +8441,64 @@ describe('Validators', () => {
'NotANumber',
],
},
+ {
+ locale: 'en-PK',
+ valid: [
+ '+923412877421',
+ '+923001234567',
+ '00923001234567',
+ '923001234567',
+ '03001234567',
+ ],
+ invalid: [
+ '+3001234567',
+ '+933001234567',
+ '+924001234567',
+ '+92300123456720',
+ '030012345672',
+ '30012345673',
+ '0030012345673',
+ '3001234567',
+ ],
+ },
+ {
+ locale: ['tg-TJ'],
+ valid: [
+ '+992553388551',
+ '+992553322551',
+ '992553388551',
+ '992553322551',
+ ],
+ invalid: [
+ '12345',
+ '',
+ 'Vml2YW11cyBmZXJtZtesting123',
+ '+995563388559',
+ '+9955633559',
+ '19676338855',
+ '+992263388505',
+ '9923633885',
+ '99255363885',
+ '66338855',
+ ],
+ },
+ {
+ locale: 'dv-MV',
+ valid: [
+ '+960973256874',
+ '781246378',
+ '+960766354789',
+ '+960912354789',
+ ],
+ invalid: [
+ '+96059234567',
+ '+96045789',
+ '7812463784',
+ '+960706985478',
+ '+960926985478',
+ 'NotANumber',
+ ],
+ },
];
let allValid = [];
@@ -8854,6 +9589,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',
@@ -8925,6 +9691,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 +9875,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',
],
});
});
@@ -9166,6 +9936,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',
@@ -9221,27 +10021,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',
+ '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: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',
+ ':?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 */
@@ -9759,6 +10557,20 @@ describe('Validators', () => {
'ab1234',
],
},
+ {
+ locale: 'LK',
+ valid: [
+ '11500',
+ '22200',
+ '10370',
+ '43000',
+ ],
+ invalid: [
+ '1234',
+ '789389',
+ '982',
+ ],
+ },
];
let allValid = [];
@@ -10256,12 +11068,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',
@@ -10591,6 +11410,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({
@@ -10660,6 +11498,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'],
@@ -10673,6 +11544,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'],
@@ -10719,7 +11615,7 @@ describe('Validators', () => {
],
});
});
- it('should validate english VAT numbers', () => {
+ it('should validate VAT numbers', () => {
test({
validator: 'isVAT',
args: ['GB'],
@@ -10749,7 +11645,6 @@ describe('Validators', () => {
'GBHA499',
],
});
-
test({
validator: 'isVAT',
args: ['IT'],
@@ -10765,7 +11660,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'],