daddyz / phonelib

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

A bit strange behavior of the parser when determining the country code #315

Open Viktor-Ivliev opened 2 months ago

Viktor-Ivliev commented 2 months ago
 Phonelib.parse('(249) 209-7272').country => "US"   - returned default
 Phonelib.parse('(249) 209-7272').valid_countries => []
 Phonelib.parse(Phonelib.parse('(249) 209-7272').e164).country => "CA"  - returned correct value

Why can't we try to identify the country after formatting the number?

Versions:

  phonelib (0.9.2)
  phonelib (0.8.8)
daddyz commented 4 weeks ago

@Viktor-Ivliev sounds similar to https://github.com/daddyz/phonelib/issues/262#issuecomment-2439863884 since I understand that you define US as default country. Try to define several default countries and then it will work:

Phonelib.default_country = [:us, :ca]