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

Incorrect validation for Maldives phone numbers #2101

Closed
anetecima opened this issue Nov 7, 2022 · 6 comments · Fixed by #2109
Closed

Incorrect validation for Maldives phone numbers #2101

anetecima opened this issue Nov 7, 2022 · 6 comments · Fixed by #2109

Comments

@anetecima
Copy link

anetecima commented Nov 7, 2022

Describe the bug
Valid Maldives phone numbers with country codes are not accepted as valid

Examples
https://codesandbox.io/s/validator-phone-number-validation-52j2tb?file=/src/App.js

https://en.wikipedia.org/wiki/Telephone_numbers_in_Maldives

@braaar
Copy link
Contributor

braaar commented Nov 8, 2022

It's not obvious from your sandbox which of your examples are supposed to be valid or not.

Could you make a list of things that should be valid according to the numbering standard, and another list that should be invalid? Then you can print the results and we can see what discrepancies exist.

Also, remember that isMobilePhone only accepts mobile phone numbers, not landlines.

@braaar
Copy link
Contributor

braaar commented Nov 8, 2022

You should probably also specify the locale in the isMobilePhone call, like so isMobilePhone(item, 'dv-MV')

@anetecima
Copy link
Author

According to documentation locale defaults to 'any' if not passed, and it works for other countries I've tested.
in tests these are used as valid numbers for Maldives - '+960973256874', '781246378', '+960766354789', '+960912354789',
Maldives phone number length is country code (+960) + 7 digits

@braaar
Copy link
Contributor

braaar commented Nov 9, 2022

My point is that if you want to test the behaviour of the maldives phone number validator, you should specify that locale.

@pano9000
Copy link
Contributor

pano9000 commented Dec 2, 2022

I am not familiar with the mobile phone numbers in the Maledives (yet), but I can see that the RegExp and your examples currently will never match:

Currently the RegExp for dv-MV is: /^(+?960)?(7[2-9]|91|9[3-9])\d{7}$/

The RegExp tries to match basically three things

  • the country code +960 (either with or without the plus sign) (or even completely optional as well)
  • a two digits, that must be 7[2-9] OR 91 OR 9[3-9]
  • a seven digits, that can be [0-9]
  • additional restriction: the RegExp does not match any strings with a space or any hyphens in it

Even if I remove the spaces and hyphens between the numbers in your example, they still fall short on the other requirements

  • 7990200_ _ -> last part missing two digits
  • 9990200_ _ -> last part missing two digits
  • 00960 302 2200 -> second part does not start with a valid digit + last part is missing two digits + RegExp de
  • +960 302 2200 -> second part does not start with a valid digit + last part is missing two digits
  • +960 332 3224 -> second part does not start with a valid digit + last part is missing two digits
  • +960 332 2802 -> second part does not start with a valid digit + last part is missing two digits
  • +960 123 4567 -> second part does not start with a valid digit + last part is missing two digits
  • +960 464 0304 -> second part does not start with a valid digit + last part is missing two digits
  • +960 771-2345_ _ -> last part missing two digits

so the question is: are these valid phone numbers?
If yes, then the RegExp would definitely need to be fixed and updated.
If not, then I guess the RegExp is doing its job. :-)

So doing some quick research here, it might actually be that the RegExp might contain an issue, see the first two lines of the document here:
https://www.cam.gov.mv/docs/Numbering_plan.pdf

I will do some more research this evening and revert back to you

@pano9000
Copy link
Contributor

pano9000 commented Dec 2, 2022

Yeah looks like the RegExp is wrong and was already wrong ever since it was added in October 2021:
c96d805

Checking previous numbering plans, seems to confirm this:
2015:
https://web.archive.org/web/20160306223623/https://www.cam.gov.mv/docs/Numbering_plan.pdf
2020:
https://web.archive.org/web/20210819115559/https://www.cam.gov.mv/docs/Numbering_plan.pdf

ALso checking some "real world" examples, they all use a total of 7 digits, not 2 + 7 digits, as the RegExp currently suggests.

Examples
e.g. see here the phone numbers here:
https://www.tourism.gov.mv/en/page/contact_the_ministry_of_tourism_maldives
Or just check any phone number of any shop on Google Maps for example:
https://goo.gl/maps/8BwaESmgP76tSt9a9

I will create a PR for this tomorrow morning at the latest to get this fixed

pano9000 added a commit to pano9000/validator.js that referenced this issue Dec 2, 2022
The RegExp and corresponding tests were testing a wrong format.
Correct format can be found in the numbering plan:
https://web.archive.org/web/20220614004138/https://cam.gov.mv/docs/Numbering_plan.pdf

fixes issue validatorjs#2101
pano9000 added a commit to pano9000/validator.js that referenced this issue Dec 2, 2022
pano9000 added a commit to pano9000/validator.js that referenced this issue Jan 28, 2023
The RegExp and corresponding tests were testing a wrong format.
Correct format can be found in the numbering plan:
https://web.archive.org/web/20220614004138/https://cam.gov.mv/docs/Numbering_plan.pdf

fixes issue validatorjs#2101
pano9000 added a commit to pano9000/validator.js that referenced this issue Jan 28, 2023
profnandaa pushed a commit that referenced this issue Jan 29, 2023
… (#2109)

* fix(isMobilePhone): fix invalid RegExp for dv-MV

The RegExp and corresponding tests were testing a wrong format.
Correct format can be found in the numbering plan:
https://web.archive.org/web/20220614004138/https://cam.gov.mv/docs/Numbering_plan.pdf

fixes issue #2101

* test(isMobilePhone): fix tests for dv-MV RegExp

associated with issue #2101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants