daddyz / phonelib

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

`valid_countries` doesn't seems like working properly #236

Closed shqear93 closed 3 years ago

shqear93 commented 3 years ago
Phonelib Version: 0.6.51
Rails Version: 6.0.4

My test case:

Phone number: 6135550130 - Canadian

Phonelib.parse('6135550130').valid_countries         #Empty Array
Phonelib.parse('6135550130').valid_for_country? 'CA' #true
Phonelib.parse('6135550130').countries               #["US"]

What is Expected:

Phonelib.parse('6135550130').countries          #["US", "CA"]
Phonelib.parse('6135550130').valid_countries    #["CA"]

this might be valid only for canadian numbers

daddyz commented 3 years ago

@shqear93 Hi, what happens here, is that when you are not specifying country gem tries to guess it. And it can't guess to add "1" as country prefix. When you run Phonelib.parse('6135550130').valid_for_country? 'CA' gem executes Phonelib.parse('6135550130', :ca). You have several options here:

shqear93 commented 3 years ago

@daddyz Thanks for your response, I actually still confused about valid_countries, isn't supposed to try the validity of the number provided against all countries?