Closed lusa closed 1 year ago
Update: Unfortunately reversing the order will not fix this for us, as now US number (Ohio area code) 2346571289
doesn't work with Canada as the first option in default_country
, but it does work when :us
is the only option or is first in the list. It appears that this array doesn't work as expected and only considers the first option in the array.
@daddyz based on a comment you made in another ticket:
yes, you just need to specify country for such numbers or in case you are talking about single country phones use default_country setting. Refer to readme
So default_country
only works for "single country" phone numbers, and so a phone number matching multiple countries as the ones I'm looking at will need to be manually checked with valid_for_country?
for each of my countries? If that's the case feel free to close.
@lusa just released new v0.8.1 with the fix
@daddyz a version change from 0.8.0
to 0.9.0
might have been better here
https://github.com/daddyz/phonelib/issues/297#issue-2135368672
Hi, we have Canada phone numbers that are being entered without the
1
prefix. This works fine ifdefault_country
is set to:ca
, but we want both[:us, :ca]
to be set as the default countries, in a way where it will try to parse as a US number, then as Canada number. But, unfortunately it is guessing other countries that are not inside the default_country array before it is guessing the correct country in the default_country array (canada).Strangely, it appears to work if the order is reversed:
[:ca, :us]
gives expected behavior. Would this be an acceptable workaround or would this clash with US numbers? Edit: See next comment. This doesn't work for some US numbers.I am on the latest version (0.8.0).
Examples: I would expect all of the following to return Canada in the countries array (implying when we run
number.e164
we get canada formatting with +1 in front of the number).