phonelib icon indicating copy to clipboard operation
phonelib copied to clipboard

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

Open mgibson8 opened this issue 8 years ago • 4 comments

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

mgibson8 avatar Feb 08 '18 13:02 mgibson8

@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 avatar Mar 04 '18 17:03 daddyz

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

daddyz avatar Apr 22 '19 04:04 daddyz

[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.

fynsta avatar Aug 08 '22 09:08 fynsta