Same country code for Canada/US
perez-alex opened this issue · 2 comments
I'm using this lib to detect the country and show the appropiate flag, but it's returning US for Canada phone numbers. Is there a way to differentiate countries with the same code?
For example, this is a valid Canada phone number:
+1 204-774-4023
But after parsing it, I get that the country code is US
Hi @perez-alex,
I'm not sure it's possible. You can get a region code and then a list of country codes for this region.
Note for those finding this on Google search. You can use combine getSupportedRegions
with getCountryCodeForRegion
to identify the country code for each region (perhaps compute this once and cache it). Then iterate over all +1 regions with isValidNumberForRegion
. The first region to pass this identifies the origin country of the number.