Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disagreement between EctoPhone and ExPhoneNumber on if a number is valid #1

Open
peaceful-james opened this issue Nov 27, 2024 · 1 comment

Comments

@peaceful-james
Copy link
Contributor

iex(6)> {:ok, parsed} = ExPhoneNumber.parse("040-191240", "SE")
{:ok,
 %ExPhoneNumber.Model.PhoneNumber{
   country_code: 46,
   national_number: 40191240,
   extension: nil,
   italian_leading_zero: nil,
   number_of_leading_zeros: nil,
   raw_input: nil,
   country_code_source: nil,
   preferred_domestic_carrier_code: nil
 }}
iex(7)> ExPhoneNumber.is_valid_number?(parsed)
true
iex(8)> ExPhoneNumber.is_possible_number?(parsed)
true
iex(9)> formatted = ExPhoneNumber.format(parsed, :international)
"+46 40 19 12 40"
iex(10)> EctoPhone.sigil_PHONE(formatted, ~c"i")
** (EctoPhone.Error) is not a valid phone number
    (ecto_phone 1.1.0) lib/ecto_phone.ex:110: EctoPhone.sigil_PHONE/2
    iex:10: (file)
@peaceful-james peaceful-james changed the title Disagreement between EctoPhone and ExPhoneNumber on ifa number is valid Disagreement between EctoPhone and ExPhoneNumber on if a number is valid Nov 27, 2024
@peaceful-james
Copy link
Contributor Author

I can work around this for now by doing

EctoPhone.Parser.parse(formatted, format: :international, default_prefix: nil)

instead of using sigil_PHONE .

Maybe this is not a real issue? To me, it seems strange that the configured "default prefix" is always used. ExPhoneNumber parsed the number and correctly identified the prefix as 46.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant