Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for Malaysian mobile phones #507

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
coverage
test/npm-debug.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Passing anything other than a string is an error.
- **isLength(str, options)** - check if the string's length falls in a range. `options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs.
- **isLowercase(str)** - check if the string is lowercase.
- **isMACAddress(str)** - check if the string is a MAC address.
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-SY', 'zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK', 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU', 'nb-NO', 'nn-NO', 'vi-VN', 'en-NZ', 'en-IN', 'es-ES', 'de-DE', 'fi-FI']`).
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-SY', 'zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK', 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU', 'nb-NO', 'nn-NO', 'vi-VN', 'en-NZ', 'en-IN', 'es-ES', 'de-DE', 'fi-FI', 'ms-MY']`).
- **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.
- **isNull(str)** - check if the string is null (has a length of zero).
Expand Down
2 changes: 2 additions & 0 deletions lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var alpha = exports.alpha = {
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i,
'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
'ru-RU': /^[А-ЯЁа-яё]+$/i,
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/
Expand All @@ -20,6 +21,7 @@ var alphanumeric = exports.alphanumeric = {
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[0-9A-ZÉËÏÓÖÜ]+$/i,
'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
'ru-RU': /^[0-9А-ЯЁа-яё]+$/i,
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/
Expand Down
1 change: 1 addition & 0 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var phones = {
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand Down
1 change: 1 addition & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const phones = {
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand Down
84 changes: 55 additions & 29 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2063,36 +2063,62 @@ describe('Validators', function () {
],
args: ['es-ES'],
});
});

test({
validator: 'isMobilePhone',
valid: [
'+358505557171',
'0455571',
'0505557171',
'358505557171',
'04412345',
'0457 123 45 67',
'+358457 123 45 67',
'+358 50 555 7171',
],
invalid: [
'12345',
'',
'045557',
'045555717112312332423423421',
'Vml2YW11cyBmZXJtZtesting123',
'010-38238383',
'+3-585-0555-7171',
'+9676338855',
'19676338855',
'6676338855',
'+99676338855',
'044123',
'019123456789012345678901',
],
args: ['fi-FI'],
test({
validator: 'isMobilePhone',
valid: [
'+358505557171',
'0455571',
'0505557171',
'358505557171',
'04412345',
'0457 123 45 67',
'+358457 123 45 67',
'+358 50 555 7171',
],
invalid: [
'12345',
'',
'045557',
'045555717112312332423423421',
'Vml2YW11cyBmZXJtZtesting123',
'010-38238383',
'+3-585-0555-7171',
'+9676338855',
'19676338855',
'6676338855',
'+99676338855',
'044123',
'019123456789012345678901',
],
args: ['fi-FI'],
});

test({
validator: 'isMobilePhone',
valid: [
'+60128228789',
'+60195830837',
'+6019-5830837',
'+6019-5830837',
'0128737867',
'01468987837',
'016-2838768',
'016 2838768',
],
invalid: [
'12345',
'601238788657',
'088387675',
'16-2838768',
'032551433',
'6088-387888',
'088-261987',
'1800-88-8687',
'088-320000',
],
args: ['ms-MY'],
});
});

it('should validate currency', function () {
Expand Down
3 changes: 3 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i,
'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
'ru-RU': /^[А-ЯЁа-яё]+$/i,
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/
Expand All @@ -398,6 +399,7 @@
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[0-9A-ZÉËÏÓÖÜ]+$/i,
'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
'ru-RU': /^[0-9А-ЯЁа-яё]+$/i,
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/
Expand Down Expand Up @@ -853,6 +855,7 @@
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand Down
Loading