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

[Question] Allow only phone numbers with international prefix #195

Open
collimarco opened this issue Jul 20, 2020 · 2 comments
Open

[Question] Allow only phone numbers with international prefix #195

collimarco opened this issue Jul 20, 2020 · 2 comments

Comments

@collimarco
Copy link

I have a Rails application that allows users to enter their phone number. Users are from different countries and I don't know the country for each user.

Is it possible to force users to enter only full phone numbers that include the country code?

# example
validates :phone_number, phone: true, require_international_prefix: true

This is especially useful for Whatsapp which requires "a full phone number in international format".

@collimarco
Copy link
Author

collimarco commented Jul 27, 2020

I made some experiments... At first I thought that using the normal validation did the job and refused numbers without an international prefix. Then I noticed that if the national number starts with something that seems an international prefix, then the number is accepted.

Example:

  • +41 442511234: valid and gives correct result
  • 442511234: reported as valid by this library, as if it was a GB number, while it is actually a CH number without international prefix!

Second example seems a bug to me... doesn't need to have a + or 00 in front of it in order to be a number with international prefix? In my opinion it should be considered invalid (i.e. country_code should be considered nil in the second example)

@daddyz
Copy link
Owner

daddyz commented Oct 13, 2020

In latest version "442511234" is not valid, but I will keep this as enhancement to expect for e164 only in validator for certain params. Thanks for reporting

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

2 participants