Skip to content

Commit 785ff94

Browse files
committed
Extended with mobil phone validation, and updated the readme
1 parent b4acee3 commit 785ff94

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Passing anything other than a string is an error.
5555
- **contains(str, seed)** - check if the string contains the seed.
5656
- **equals(str, comparison)** - check if the string matches the comparison.
5757
- **isAfter(str [, date])** - check if the string is a date that's after the specified date (defaults to now).
58-
- **isAlpha(str [, locale])** - check if the string contains only letters (a-zA-Z). Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'tr-TR']`) and defaults to `en-US`.
59-
- **isAlphanumeric(str [, locale])** - check if the string contains only letters and numbers. Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'tr-TR']`) and defaults to `en-US`.
58+
- **isAlpha(str [, locale])** - check if the string contains only letters (a-zA-Z). Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'tr-TR']`) and defaults to `en-US`.
59+
- **isAlphanumeric(str [, locale])** - check if the string contains only letters and numbers. Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'tr-TR']`) and defaults to `en-US`.
6060
- **isAscii(str)** - check if the string contains ASCII chars only.
6161
- **isBase64(str)** - check if a string is base64 encoded.
6262
- **isBefore(str [, date])** - check if the string is a date that's before the specified date.
@@ -85,7 +85,7 @@ Passing anything other than a string is an error.
8585
- **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.
8686
- **isLowercase(str)** - check if the string is lowercase.
8787
- **isMACAddress(str)** - check if the string is a MAC address.
88-
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-SY', 'cs-CZ', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'ms-MY', 'nb-NO', 'nn-NO', 'pt-PT', 'ru-RU', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-TW']`).
88+
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-SY', 'cs-CZ', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'hu-HU', 'ms-MY', 'nb-NO', 'nn-NO', 'pt-PT', 'ru-RU', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-TW']`).
8989
- **isMongoId(str)** - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
9090
- **isMultibyte(str)** - check if the string contains one or more multibyte chars.
9191
- **isNull(str)** - check if the string is null (has a length of zero).

src/lib/isMobilePhone.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const phones = {
1717
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
1818
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
1919
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
20+
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
2021
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
2122
'nb-NO': /^(\+?47)?[49]\d{7}$/,
2223
'nn-NO': /^(\+?47)?[49]\d{7}$/,

0 commit comments

Comments
 (0)