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

Add documentation #13

Open
alexgleason opened this issue Jan 12, 2022 · 2 comments
Open

Add documentation #13

alexgleason opened this issue Jan 12, 2022 · 2 comments

Comments

@alexgleason
Copy link

I don't understand how to use this library.

** (Ecto.ChangeError) value "+15551234567" for MyApp.Challenge.Sms.SmsRecord.phone in insert does not match type EctoPhoneNumber

@Jaza
Copy link

Jaza commented May 7, 2024

I get the same error, when I have this schema:

...
schema "users" do
  field :phone_number, EctoPhoneNumber
  ...
end
...

And when I try this in iex:

MyApp.Repo.insert(%MyApp.User{phone_number: "+61412345678"})

Help please?

@Jaza
Copy link

Jaza commented May 7, 2024

After further trial and error, I figured out that this works:

{:ok, phone_number} = EctoPhoneNumber.cast("+61412345678")
MyApp.Repo.insert(%MyApp.User{phone_number: phone_number})

(and that first line raises a MatchError if the input is an invalid phone number).

But surely that's not the correct way to use this library?

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

2 participants