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

international format fails on german mobile numbers #168

Open
Shonyyyyy opened this issue Jun 18, 2019 · 5 comments
Open

international format fails on german mobile numbers #168

Shonyyyyy opened this issue Jun 18, 2019 · 5 comments
Labels
missing validation data data for some prefix/country is missing in the souce

Comments

@Shonyyyyy
Copy link

When parsing a german phone number string by calling Phonelib.parse().international the parsed number gets an extra country_code number.

E.g.:
Phonelib.parse('491511234567').international returns +49 491 511234567.
Expected would be: +49 151 1234567.

This only appears when the following is given:

  • The area number has to be 15x or 161.
  • The local number has less than 8 digits.
@danborden1
Copy link

In rails, this behavior can be fixed by adding Phonelib.strict_double_prefix_check = true to config/initializers/phonelib.rb

@daddyz
Copy link
Owner

daddyz commented Jun 27, 2019

@Shonyyyyy number 491511234567 is not valid by google's regex, their regex says that there should be 8 symbols after 151.

Phonelib.parse('49 151 12345678').international # => "+49 1511 2345678"

Since number is not valid, for countries with option to have double country prefix, library tries to add additional country prefix and reparse, and in case it's valid, the new number will be returned. So suggestion offered by @chiefjuss is not good.

 Phonelib.parse('+49 151 1234567').valid? # => false

In case 7 digits numbers are valid, you need to open an issue in original google lib

@daddyz daddyz added the missing validation data data for some prefix/country is missing in the souce label Jun 27, 2019
@Shonyyyyy
Copy link
Author

Shonyyyyy commented Jul 1, 2019

ok, thank you very much so far. I will try out that strict_double_prefix_check or try to use the validation properly before saving. I will let you know.

@krtschmr
Copy link

wiki says

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

015xx-xxxxxxx, 016x-xxxxxxx, 017x-xxxxxxx
Mobile numbers are assigned non-geographic area codes starting with 015, 016 and 017 and have a length of 3 or 4 digits without the trunk prefix. The numbers have a total length of ten or eleven digits without the trunk prefix: numbers starting with 17 or 16 are 10 digits long except 176 and 1609, which are 11 digits long like the numbers starting with 15.
Network operators issue area codes as listed in the following table.

so i assume 151 1234567 has a lenght of 10 and should be valid? guess google is doing wrong?

@daddyz
Copy link
Owner

daddyz commented Aug 27, 2019

@krtschmr As I saw they are not accepting wiki as official data source, they require links to some authoritative source. Note that prefix 015xx is written with 2 x while 016x and 017x has only 1. I am not sure if it is valid or not, but anyway issue should be raised for them in case this is an error. If I am adding additional number for 015 it works:

Phonelib.parse('4915111234567').international # => "+49 1511 1234567"

Currently google library still returns +49 491 511234567 while parsing 491511234567

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing validation data data for some prefix/country is missing in the souce
Projects
None yet
Development

No branches or pull requests

5 participants
@daddyz @Shonyyyyy @krtschmr @danborden1 and others