title: How To Modify Value In Changeset - Elixir?
body: <p>I am new to <code>phoenix framework</code>,lets say i  have a model like follow with  changeset</p>
  
  <pre><code>schema "users" do
   field :name, :string
   field :email, :string
   field :countryCode, :string
   field :phone, :string
  end
  
  def changeset_user_register(struct, params \\%{}) do
    struct
    |&gt; cast(params, [:name, :email, :countryCode, :phone])
    |&gt; validate_required(:name, [message: "Name Must Not Be Empty"])
    |&gt; validate_required(:countryCode, [message: "countryCode Must Not Be Empty"])
    |&gt; validate_required(:phone, [message: "Phone Number Must Not Be Empty"])
    |&gt; valid_phone_number
  end
  </code></pre>
  
  <p>params from form looks like <code>%{name: 'elixir', countryCode: 'IN', phone: '97989*****'}</code></p>
  
  <p>i am currently using <a href="https://github.com/socialpaymentsbv/ex_phone_number" rel="noreferrer">ex_phone_number</a> to validate phone number, my custom validator <code>valid_phone_number</code> looks like follow </p>
  
  <pre><code>defp valid_phone_number(struct) do
  countryCode = get_field(struct, :countryCode) #get_field used to get values from struct
  phone = get_field(struct, :phone)
  case ExPhoneNumber.parse(phone, countryCode) do
    {:ok, phone_number} -&gt;
      if ExPhoneNumber.is_valid_number?(phone_number) do
        e156_number = ExPhoneNumber.format(phone_number, :e164)
        %{struct | phone: e156_number}
        struct
      else
        add_error(struct, :phone, "Invalid Phone Number")
      end
    {:error, phone_number}-&gt;
      struct
   end
  end
  </code></pre>
  
  <p>Instead of storing countryCode and phone in differnt column, I am trying to store <code>e164</code> format number to my database so i modify the number <code>e156_number = ExPhoneNumber.format(phone_number, :e164)</code>in <code>changeset</code> after checking <code>phone number is valid</code>.when i trying to update <code>phone</code> in struct like follow <code>%{struct | phone: e156_number}</code> value is not updating instead it stores value returned from form <code>%{phone: '97989*****'}</code>, what mistake i made here and how can i remove countryCode also in changeset?</p>