Phone validation ecto model
When you end up with a pyramid of if-else clauses like this, it's sometimes a good idea to use cond instead.  cond lets you specify a bunch of clauses, and picks the first one that matches.

For example:

def valid_phone(changeset, field) do
  phone = get_field(changeset, field)
  cond do
    phone == nil -&gt; 
      changeset
    String.length(phone) != 10 -&gt; 
      add_error(changeset, field, "n'est pas valide")
    true -&gt;
      changeset
  end
end


Of course, that can be simplified further into

def valid_phone(changeset, field) do
  phone = get_field(changeset, field)
  cond do
    phone != nil and String.length(phone) != 10 -&gt; 
      add_error(changeset, field, "n'est pas valide")
    true -&gt;
      changeset
  end
end


Which can be simplified further, because any cond with one clauses &amp; a true is really just a fancy if-else expression:

def valid_phone(changeset, field) do
  phone = get_field(changeset, field)
  if phone != nil &amp;&amp; String.length(phone) != 10 do
    add_error(changeset, field, "n'est pas valide")
  else
    changeset
  end
end