tnederlof

tnederlof

Phone Number Form Validation

I have several forms where I want to save the phone numbers of users. In the actual database the field is a string and I would like to save in +160277688 format where 1 is country code, then area code then the number.

When I think about user inputs and enforce via my change set and form itself, I am debating how much logic goes into the change set versus closer to the form itself. Has anyone tackled phone numbers and wanted to save in a particular format?

First Post!

LostKobrakai

LostKobrakai

Personally I feel there are a few ways to go about this depending on how needs to work with the data.

  • Only used by real people: Store the number as supplied as string.
  • Used by people, but format enforced: Use e.g. a regex to enforce the format, but don’t expect it to be perfect.
  • Just not just by people: Store the input, but also normalized forms / parts e.g. by using libphonenumber

Most Liked

f0rest8

f0rest8

Might not need this anymore, but in this thread I mention a new guide I just wrote where I use ex_phone_number to handle international phone number validations and formatting in a Live View.

Hope it helps :heart:

dimitarvp

dimitarvp

The ex_phone_number library could be useful for you.

thinkingcat

thinkingcat

This might really help you @tnederlof. It uses the ex_phone_number library and creates a custom type for casting the e164 phone number into Ecto. See the cast function:

https://github.com/surgeventures/ecto-phone-number/blob/master/lib/ecto_phone_number/ecto_phone_number.ex

I am working on a similar issue, no affiliation with them, just found this gem! Many thanks to them :slight_smile:

https://github.com/surgeventures/ecto-phone-number

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement