daddyz / phonelib

Ruby gem for phone validation and formatting using google libphonenumber library data
MIT License
1.04k stars 130 forks source link

Not getting the full dial code from Dominican Republic/Bahamas/Puerto Rico numbers #220

Open AdamJacobson opened 3 years ago

AdamJacobson commented 3 years ago

Parsing a valid DO number does return 'DO' as the country:

2.7.2 :031 > Phonelib.parse("+1 809-538-0020").country
 => "DO"

But the country_code for dialing is simply returned as '1' which is the same for US/CA making country information lookups using this data problematic. Twilio specifically gives ["+1829", "+1809", "+1849"] as the possible codes for DO.

2.7.2 :032 > Phonelib.parse("+1 809-538-0020").country_code
 => "1"

Is this a bug or is there a better way to get the full dial code that I am not aware of? I've noticed similar problems with other countries that have the dial code start with '1', including Bahamas and Puerto Rico.

daddyz commented 3 years ago

@AdamJacobson this gem's data is based on google libphonenumber and it has "1" as country code since it is required for proper parsing, I will try to find a way to solve your issue.

philihp commented 3 years ago

please ensure that Puerto Rico phone numbers are still part of the US. :heart:

Phonelib.parse("+1 787-671-1234").country_code
=> "US"