Skip to content

Commit

Permalink
feat: Validation for dominica phone number added
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Brens authored and Rafael Brens committed Nov 30, 2024
1 parent 86911d8 commit a030852
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Validator | Description
**isMailtoURI(str, [, options])** | check if the string is a [Mailto URI format][Mailto URI Format].<br/><br/>`options` is an object of validating emails inside the URI (check `isEmail`s options for details).
**isMD5(str)** | check if the string is a MD5 hash.<br/><br/>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][MIME Type] format.
**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>`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-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', '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']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).<br/><br/>`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,<br/><br/>`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-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', en-DM, 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', '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']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).<br/><br/>`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.<br/><br/>`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 `.`).<br/><br/>`locale` determines 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', 'eo', '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']`.
Expand Down
1 change: 1 addition & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const phones = {
'en-AG': /^(?:\+1|1)268(?:464|7(?:1[3-9]|[28]\d|3[0246]|64|7[0-689]))\d{4}$/,
'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}$))/,
'en-BS': /^(\+?1[-\s]?|0)?\(?242\)?[-\s]?\d{3}[-\s]?\d{4}$/,
'en-DM': /^(\+?1|0)767(?:2(?:[2-4689]|7[0-4])|31[5-7]|4(?:[37]|6[0-4])|50[1-9]|642[0-4]|76[89])\d{4}$/,
'en-GB': /^(\+?44|0)7[1-9]\d{8}$/,
'en-GG': /^(\+?44|0)1481\d{6}$/,
'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|53|28|55|59)\d{7}$/,
Expand Down
28 changes: 28 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10731,6 +10731,34 @@ describe('Validators', () => {

],
},
{
locale: 'en-DM',
valid: [
'+17672345678',
'17672345678',
'7672345678',
'+17674545678',
'17673725678',
'7676325678',
'+17672505678',
'17677625678',
'7673155678',
'7674375678'

Check failure on line 10746 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Missing trailing comma

Check failure on line 10746 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Missing trailing comma

Check failure on line 10746 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Missing trailing comma

Check failure on line 10746 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Missing trailing comma

Check failure on line 10746 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Missing trailing comma

Check failure on line 10746 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Missing trailing comma

Check failure on line 10746 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Missing trailing comma
],
invalid: [
'+17612345678',
'12672345678',
'7672345',
'767234567',
'76723456789',
'+1647234567',
'867234567',
'This should fail',
'+176723456',
'76723456',
'7672'

Check failure on line 10759 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Missing trailing comma

Check failure on line 10759 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Missing trailing comma

Check failure on line 10759 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Missing trailing comma

Check failure on line 10759 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Missing trailing comma

Check failure on line 10759 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Missing trailing comma

Check failure on line 10759 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Missing trailing comma

Check failure on line 10759 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Missing trailing comma
]

Check failure on line 10760 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Missing trailing comma

Check failure on line 10760 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Missing trailing comma

Check failure on line 10760 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Missing trailing comma

Check failure on line 10760 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Missing trailing comma

Check failure on line 10760 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Missing trailing comma

Check failure on line 10760 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Missing trailing comma

Check failure on line 10760 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Missing trailing comma
}

Check failure on line 10761 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Missing trailing comma

Check failure on line 10761 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Missing trailing comma

Check failure on line 10761 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Missing trailing comma

Check failure on line 10761 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Missing trailing comma

Check failure on line 10761 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Missing trailing comma

Check failure on line 10761 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Missing trailing comma

Check failure on line 10761 in test/validators.test.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Missing trailing comma
];

let allValid = [];
Expand Down

0 comments on commit a030852

Please sign in to comment.