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

German phone numbers starting with "1" are considered invalid if prefixed by a "+" #331

Closed
gabypancu opened this issue Jan 10, 2025 · 3 comments
Labels
missing validation data data for some prefix/country is missing in the souce

Comments

@gabypancu
Copy link

gabypancu commented Jan 10, 2025

German phone numbers that start with a "1" (after the "49" country code) are wrongly considered invalid if there is a "+" at the start of the number.

Phonelib.parse("+491127690778", :de).valid?
=> false
Phonelib.parse("491127690778", :de).valid?
=> true

The two are parsed differently, with a notable difference in the national number - one includes the country code 49 and one doesn't.

Phonelib.parse("+491127690778", :de)
=> #<Phonelib::Phone:0x000000011dadfed0 @original="+491127690778", @extension="", @sanitized="491127690778", @original_s="+491127690778", @data={"DE"=>{:id=>"DE", :country_code=>"49", :international_prefix=>"00", :national_prefix=>"0", :mobile_number_portable_region=>"true", :double_prefix=>true, :national=>"1127690778", :format=>{:pattern=>"(\\d+)(\\d{3})(\\d{4})", :format=>"$1 $2 $3"}, :valid=>[], :possible=>[:premium_rate, :toll_free, :shared_cost, :pager, :uan, :fixed_or_mobile]}}, @national_number="1127690778">
Phonelib.parse("491127690778", :de)
=> #<Phonelib::Phone:0x000000011d3c1a90 @original="491127690778", @extension="", @sanitized="491127690778", @original_s="491127690778", @data={"DE"=>{:id=>"DE", :country_code=>"49", :international_prefix=>"00", :national_prefix=>"0", :mobile_number_portable_region=>"true", :double_prefix=>true, :national=>"491127690778", :format=>{:pattern=>"(\\d{3})(\\d{3,12})", :national_prefix_formatting_rule=>"$NP$FG", :leading_digits=>"2(?:0[1-389]|12[0-8])|3(?:[35-9][15]|4[015])|906|2(?:[13][14]|2[18])|(?:2[4-9]|4[2-9]|[579][1-9]|[68][1-8])1", :format=>"$1 $2"}, :valid=>[:fixed_line], :possible=>[:toll_free, :shared_cost, :pager, :uan, :voicemail, :fixed_line]}}, @national_number="491127690778">

When the country code is omitted, we also consider a number starting with "1" to be invalid:

Phonelib.parse("1577374052", :de).valid?
=> false
Phonelib.parse("2577374052", :de).valid?
=> true

The regex likely needs to be updated, as mobile phone numbers in Germany start with "1"

@daddyz
Copy link
Owner

daddyz commented Feb 3, 2025

@gabypancu that happens due to country calling code (49) being also a valid area code, and numbers have variable lengths. When you are using + it instructs the gem that you provided the full e164 number. When + is omitted gem will try to add the country code after guessing the country (Phonelib.parse("491127690778", :de).e164 # => "+49491127690778" ).
The number starting with "1" is also parsed as invalid in original libphonenumber. You can check it here and open an issue for them. Gem's data is based on it.

@daddyz daddyz added the missing validation data data for some prefix/country is missing in the souce label Feb 3, 2025
@gabypancu
Copy link
Author

I see. I've created an issue with libphonenumber and mentioned that with or without a plus, the result is not correct

@gabypancu
Copy link
Author

Closing the issue as libphonenumber has confirmed that the phone number I provided is invalid
https://partnerissuetracker.corp.google.com/issues/394116702

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

2 participants