Skip to content

Commit

Permalink
Added support for Belgian phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanEndare committed Aug 25, 2016
1 parent a8b3eba commit 0990d16
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Passing anything other than a string is an error.
- **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])** - 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`.
- **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`.
- **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', 'fr-BE', 'hu-HU', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'tr-TR']`) and defaults to `en-US`.
- **isAscii(str)** - check if the string contains ASCII chars only.
- **isBase64(str)** - check if a string is base64 encoded.
- **isBefore(str [, date])** - check if the string is a date that's before the specified date.
Expand Down
4 changes: 3 additions & 1 deletion lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nl-BE': /^(\+?32|0)4?\d{8}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand All @@ -48,6 +49,7 @@ var phones = {

// aliases
phones['en-CA'] = phones['en-US'];
phones['fr-BE'] = phones['nl-BE'];

function isMobilePhone(str, locale) {
(0, _assertString2.default)(str);
Expand All @@ -56,4 +58,4 @@ function isMobilePhone(str, locale) {
}
return false;
}
module.exports = exports['default'];
module.exports = exports['default'];
2 changes: 2 additions & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nl-BE': /^(\+?32|0)4?\d{8}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand All @@ -37,6 +38,7 @@ const phones = {

// aliases
phones['en-CA'] = phones['en-US'];
phones['fr-BE'] = phones['nl-BE'];

export default function isMobilePhone(str, locale) {
assertString(str);
Expand Down
48 changes: 48 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,54 @@ describe('Validators', function () {
],
args: ['ms-MY'],
});

test({
validator: 'isMobilePhone',
valid: [
'0470123456',
'+32470123456',
'32470123456',
'021234567',
'+3221234567',
'3221234567',
],
invalid: [
'12345',
'+3212345',
'3212345',
'04701234567',
'+3204701234567',
'3204701234567',
'0212345678',
'+320212345678',
'320212345678'
],
args: ['fr-BE'],
});

test({
validator: 'isMobilePhone',
valid: [
'0470123456',
'+32470123456',
'32470123456',
'021234567',
'+3221234567',
'3221234567',
],
invalid: [
'12345',
'+3212345',
'3212345',
'04701234567',
'+3204701234567',
'3204701234567',
'0212345678',
'+320212345678',
'320212345678'
],
args: ['nl-BE'],
});
});

it('should validate currency', function () {
Expand Down
4 changes: 3 additions & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nl-BE': /^(\+?32|0)4?\d{8}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand All @@ -902,6 +903,7 @@

// aliases
phones['en-CA'] = phones['en-US'];
phones['fr-BE'] = phones['nl-BE'];

function isMobilePhone(str, locale) {
assertString(str);
Expand Down Expand Up @@ -1128,4 +1130,4 @@

return validator;

}));
}));
Loading

0 comments on commit 0990d16

Please sign in to comment.