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

When setting default_country to Germany, Phonelib incorrectly returns numbers as German #128

Open
mgibson8 opened this issue Feb 8, 2018 · 3 comments

Comments

@mgibson8
Copy link

mgibson8 commented Feb 8, 2018

When setting the default country like so..

Phonelib.default_country = "DE"

Phonelib appears to return almost all numbers I tested as German numbers. Out of the 67 numbers I tried, from 60 different countries only 3 returned correctly using the following code, the rest being returned as Germany.

Phonelib.parse(number).country
@daddyz
Copy link
Owner

daddyz commented Mar 4, 2018

@mgibson8 It's hard to determine whether number is valid or not in case of Germany. Valid number can be from 5 to 15 digits after the country code. Such regex is really awesome.
I can provide you with additional setting like prefer country detection prior to default country parsing, meaning phonelib will try to detect country by prefix, and in case it won't be able to parse as valid number will failover to default country.
Will it suite your needs?

@daddyz
Copy link
Owner

daddyz commented Apr 22, 2019

@mgibson8 there is now a Phonelib.strict_double_prefix_check that can help to overcome this issue. Anyway if you can share examples please.

@fynsta
Copy link
Contributor

fynsta commented Aug 8, 2022

[1] pry(main)> Phonelib.default_country = nil
=> nil
[2] pry(main)> Phonelib.parse('​+41900 123 123').country
=> "CH"
[3] pry(main)> Phonelib.default_country = 'DE'
=> "DE"
[4] pry(main)> Phonelib.parse('​+41900 123 123').country
=> "DE"
[5] pry(main)> Phonelib.strict_double_prefix_check = true
=> true
[6] pry(main)> Phonelib.parse('​+41900 123 123').country
=> "DE"

@daddyz The strict_double_prefix_check option does not seem to do fix this issue. Or am I misunderstanding anything here? I would expect a number with a '+41' prefix to first be checked for the swiss country regex, and then for the default country.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants