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

isMobilePhone for Belgian phone numbers validates also non mobile phone numbers #1684

Closed
h3llrais3r opened this issue Jun 25, 2021 · 10 comments

Comments

@h3llrais3r
Copy link

h3llrais3r commented Jun 25, 2021

Describe the bug
The isMobilePhone() validator should only validate mobile phone numbers.
Currently it seems that it also validates the local/regional fixed phone numbers.
Reference: https://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium

Examples
Valid ones:

  • 0470123456
  • +32470123456
  • 32470123456

Invalid ones (but valid local/regional fixed phone numbers):

  • 021234567
  • +3221234567
  • 3221234567

Examples are taking from the test cases:
valid mobile phone numbers: https://github.com/validatorjs/validator.js/blob/master/test/validators.js#L7290-L7292
valid fixed phone numbers (but no valid mobile phone numbers): https://github.com/validatorjs/validator.js/blob/master/test/validators.js#L7293-L7295

Additional context
Validator.js version: 13.6.0
Node.js version: 12.x
OS platform: windows

Possible fix (not fully tested):
Replace regex /^(\+?32|0)4?\d{8}$/ by /^(\+?32|0)4\d{8}$/
at https://github.com/validatorjs/validator.js/blob/master/src/lib/isMobilePhone.js#L97

This should only allow:

  • 04xxxxxxxx (10 digits, 04 followed by 8 digits)
  • 324xxxxxxxx (9 digits, leading 0 omitted, after country code without +)
  • +324xxxxxxxx (9 digits, lading 0 omitted, after country code)

You can even go further and also only allow the range of 04xx numbers by provider (see wikipedia), but I think that would go too far and it also has a risk that you need to adapt your regex if a new provider (or range) is added.

@rubiin
Copy link
Member

rubiin commented Jul 5, 2021

Would you like to create a PR?

@h3llrais3r
Copy link
Author

@rubiin Yes, can make a PR if you want.
But just to be sure: should isMobilePhone() only validate mobile phone numbers, or also fixed phone numbers?
Because in Belgium, both are used, and both have a different format.

@fedeci
Copy link
Contributor

fedeci commented Jul 13, 2021

It should only validate mobile phone numbers.

@profnandaa
Copy link
Member

Thanks for noting, sure, make a PR.

@divikshrivastava
Copy link
Contributor

@profnandaa @ezkemboi Can I raise a PR for this issue, I have verified the given regex with some random Belgian numbers I could find online.

@tux-tn
Copy link
Member

tux-tn commented Oct 2, 2021

@divikshrivastava sure, go ahead!

@divikshrivastava
Copy link
Contributor

divikshrivastava commented Oct 2, 2021

Thanks for go ahead! Added the PR @tux-tn
#1746

@YASH3166
Copy link

YASH3166 commented Oct 8, 2021

Can I raise a PR for this issue?

@ezkemboi
Copy link
Member

ezkemboi commented Oct 8, 2021

@YASH3166 seems Pr has been raised

@tux-tn
Copy link
Member

tux-tn commented Oct 8, 2021

Closing since PR raised #1746 and merged. Sorry @YASH3166 , feel free to pick another issue!

@tux-tn tux-tn closed this as completed Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants