<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="83945" data-post-id="83945">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Lets say you have</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Demo do

  def rut?(rut) when is_binary(rut)do
    rut
    |&gt; clean()
    |&gt; valid?()
  end
  def rut?(_) do
    false
  end

  defp clean(value),
    do: Regex.replace(~r/[^0-9K]/, String.upcase(value), "")

  defp valid?(rut) do
    reversed = String.reverse(rut)
    if verify(reversed) do
      {digits, check} = split(reversed)

      check == checksum(digits)

    else
      false
    end
  end

  defp verify(reversed),
    do: Regex.match?(~r/^(\d|K)\d{7,8}$/, reversed)

  defp split(reversed) do
    [check_digit | rest] = String.graphemes(reversed)

    digits = Enum.map(rest, &amp;(String.to_integer(&amp;1)))
    check =
      case check_digit do
        "K" -&gt; 10
        _ -&gt; String.to_integer(check_digit)
      end
    {digits, check}
  end

  defp checksum(digits) do
    result =
      digits
      |&gt; length()
      |&gt; make_coefficients()
      |&gt; Enum.zip(digits)
      |&gt; Enum.reduce(0,&amp;to_sum/2)
      |&gt; Integer.mod(11)

    case (11 - result) do
      11 -&gt; 0
      n -&gt; n
    end
  end

  defp make_coefficients(amount) do
    (2..7)
    |&gt; Stream.cycle()
    |&gt; Enum.take(amount)
  end

  def to_sum({a,b}, sum),
    do: a * b + sum

end

IO.inspect(Demo.rut?("30.686.957-4")) # true
IO.inspect(Demo.rut?("306869574"))    # true
IO.inspect(Demo.rut?("30.686.954-K")) # true
IO.inspect(Demo.rut?("30686954K"))    # true
IO.inspect(Demo.rut?("3068695K4"))    # false
IO.inspect(Demo.rut?("1938909K"))     # true
IO.inspect(Demo.rut?("19389093"))     # false
IO.inspect(Demo.rut?("0"))            # false
IO.inspect(Demo.rut?(""))             # false
IO.inspect(Demo.rut?(nil))            # false
IO.inspect(Demo.rut?(306869574))      # false
</code></pre>
<p>then you should be able to:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Medica.AppointmentView do
  import Demo, only: [ rut?: 1 ]

  # ...

end
</code></pre>
<p>and then</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;%= if rut?(appointment.rut_paciente) do %&gt;
</code></pre>
<p>should work.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="83945" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-83945" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="83945"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="83975" data-post-id="83975">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Lily" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Lily/120/10169_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Lily
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/peerreynders" rel="nofollow">@peerreynders</a> My God, but… does it work if I used mix phoenix.new instead of mix phx.new?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="83975" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-83975" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="83975"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="83977" data-post-id="83977">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>1.3 only released about a year ago (which introduced the <code>phx</code> mix tasks) - the technique was in use well before that so I doubt that it will make a difference whether you used <code>mix phx.new</code> or <code>mix phoenix.new</code> - it should work in either case.</p>
<ul>
<li>Functions defined inside or imported into the <code>View</code> module are available inside the rendered templates.</li>
<li>In general one should prefer to <em>not</em> have detailed logic inside the template itself. It’s usually better to put that logic into a function inside the associated <code>View</code> module (or <code>import</code> it into the <code>View</code> module from another module) - and then just use the function inside the template.</li>
</ul> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="83977" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-83977" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="83977"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="83978" data-post-id="83978">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Lily" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Lily/120/10169_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Lily
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m really ashamed I have to ask this, but… From the script you gave me, what part I can paste exactly as is shown and what part I can’t?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="83978" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-83978" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="83978"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #25"></div>
  </section>
</div>
    <div class="postbit" id="83981" data-post-id="83981">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="joaoevangelista" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joaoevangelista/120/39742_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  joaoevangelista
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>As I see on the implementation you can use the whole module Demo, except the <code>IO.inspect</code> calls, just use a meaningful name such as <code>RutChecker</code> and place in a file on your source tree, then import on your view as shown just changing Demo to the name you have it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="83981" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-83981" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="83981"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #26"></div>
  </section>
</div>
    <div class="postbit" id="83982" data-post-id="83982">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Lily" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Lily/120/10169_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Lily
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>By the way, I’m shocked you actually know the whole RUT algorithm, which is, as far as I know, a Chile thing only. You really gave me a surprise.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="83982" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-83982" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="83982"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #27"></div>
  </section>
</div>
    <div class="postbit" id="84033" data-post-id="84033">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The Google translate of <a href="https://es.wikipedia.org/wiki/Rol_%C3%9Anico_Tributario#Procedimiento_para_obtener_el_d.C3.ADgito_verificador" rel="noopener nofollow ugc">this</a> is actually readable. And other resources like <a href="https://github.com/daplay/chileno/tree/master/src/chileno" rel="noopener nofollow ugc">this</a> and <a href="https://gist.github.com/ryangreenberg/4531891" rel="noopener nofollow ugc">this</a> are also available.</p>
<p>So just a simple (not particularly good) example:</p>
<pre data-code-wrap="bash"><code class="lang-bash">$ mix phoenix.new --no-ecto medica
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir"># file: medica/lib/paciente/identificacion.ex
# Note: code in web IS reloaded, and the code in lib IS NOT
#
defmodule Paciente.Identificacion do

  def rut?(rut) when is_binary(rut)do
    rut
    |&gt; clean()
    |&gt; valid?()
  end
  def rut?(_) do
    false
  end

  # the rest ...

end

</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir"># file: medica/web/views/page_view.ex
defmodule Medica.PageView do
  use Medica.Web, :view

  import Paciente.Identificacion, only: [rut?: 1]

end
</code></pre>
<pre data-code-wrap="xml"><code class="lang-xml">      &lt;!-- in medica/web/templates/page/index.html.eex --&gt;
      &lt;%= if rut?("30.686.957-4") do %&gt;
        &lt;p&gt;PASS&lt;/p&gt;
      &lt;% else %&gt;
        &lt;p&gt;FAIL&lt;/p&gt;
      &lt;% end %&gt;
      &lt;%= if rut?("30.686.957-5") do %&gt;
        &lt;p&gt;PASS&lt;/p&gt;
      &lt;% else %&gt;
        &lt;p&gt;FAIL&lt;/p&gt;
      &lt;% end %&gt;
</code></pre>
<p>Works as expected.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="84033" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/29">Post #28</a>
	                </div>
	            </div>
              <div id="likers-container-84033" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="84033"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #28"></div>
  </section>
</div>
    <div class="postbit" id="84044" data-post-id="84044">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Lily" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Lily/120/10169_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Lily
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m sorry, but I don’t get how do I implement this so my form accepts o denies a RUT <img src="https://forum.elixirforum.com/images/emoji/apple/sob.png?v=15" title=":sob:" class="emoji" alt=":sob:" loading="lazy" width="20" height="20"> And also, I don´t get why you put:</p>
<pre><code>  &lt;%= if rut?("30.686.957-5") do %&gt;
    &lt;p&gt;PASS&lt;/p&gt;
  &lt;% else %&gt;
    &lt;p&gt;FAIL&lt;/p&gt;
  &lt;% end %&gt;
</code></pre>
<p>30.686.957-5 is not a valid RUT, the final digit should be 4, otherwise, it should be denied.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="84044" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/30">Post #29</a>
	                </div>
	            </div>
              <div id="likers-container-84044" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="84044"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #29"></div>
  </section>
</div>
    <div class="postbit" id="84046" data-post-id="84046">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Lily" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Lily/120/10169_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Lily
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>For example, in my appointment controller, I analyze the description of an appointment and watch if there’s a bad word in it:</p>
<p>def create(conn, %{“appointment” =&gt; appointment_params}) do<br>
changeset = Appointment.changeset(%Appointment{}, appointment_params)<br>
regex = ~r/(s[\w-]*e[\w-]*x[\w-]<em>o[\w-]</em>)/<br>
regex2 = ~r/(m[\w-]*i[\w-]*e[\w-]*r[\w-]*d[\w-]<em>a[\w-]</em>)/<br>
regex3 = ~r/(w[\w-]*e[\w-]*o[\w-]<em>n[\w-]</em>)/<br>
regex4 = ~r/(p[\w-]*u[\w-]*t[\w-]<em>a[\w-]</em>)/<br>
if((Regex.match?(regex, appointment_params[“descripcion”]))<br>
or (Regex.match?(regex2, appointment_params[“descripcion”]))<br>
or (Regex.match?(regex3, appointment_params[“descripcion”]))<br>
or (Regex.match?(regex4, appointment_params[“descripcion”]))) do<br>
conn<br>
|&gt; put_flash(:error, “Language!”)<br>
|&gt; render(“new.html”, changeset: changeset)<br>
else<br>
case Repo.insert(changeset) do<br>
{:ok, appointment} → <br>
conn<br>
|&gt; put_flash(:info, “Appointment created succesfully”)<br>
|&gt; redirect(to: appointmentu_path(conn, :show, appointment))<br>
{:error, changeset} → <br>
render(conn, “new.html”, changeset: changeset)<br>
end<br>
end<br>
end</p>
<p>I would like to do something similar with rut_paciente.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="84046" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/31">Post #30</a>
	                </div>
	            </div>
              <div id="likers-container-84046" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="84046"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #30"></div>
  </section>
</div>
    <div class="postbit" id="84051" data-post-id="84051">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="joaoevangelista" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joaoevangelista/120/39742_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  joaoevangelista
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think the misspelled RUT was just an example, and the <code>&lt;p&gt;</code> tags as something you would need to do. See in the first example you gave you were using to filter  the rows on the table in you were putting on the page, thus the example with <code>&lt;p&gt;</code> tags.</p>
<p>Now if you want to add a validation over the form input so you can alert your users when they type wrong RUT you justs need to apply before the regex if, or even better, apply it on Ecto.Changeset validations.</p>
<p>Here are some snippets.</p>
<p>First if you decide to use on your controller next to language check</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def create(conn, %{"appointment" =&gt; appointment_params}) do
    changeset = Appointment.changeset(%Appointment{}, appointment_params)
    regex = ~r/(s[\w-]*e[\w-]*x[\w-]o[\w-])/
    regex2 = ~r/(m[\w-]*i[\w-]*e[\w-]*r[\w-]*d[\w-]a[\w-])/
    regex3 = ~r/(w[\w-]*e[\w-]*o[\w-]n[\w-])/
    regex4 = ~r/(p[\w-]*u[\w-]*t[\w-]a[\w-])/
    
    # we use cond here to check against many "ifs" think of nested if/else
    cond do
      (Regex.match?(regex, appointment_params["descripcion"]))
      or (Regex.match?(regex2, appointment_params["descripcion"]))
      or (Regex.match?(regex3, appointment_params["descripcion"]))
      or (Regex.match?(regex4, appointment_params["descripcion"])) -&gt;
        conn
        |&gt; put_flash(:error, "Language!")
        |&gt; render("new.html", changeset: changeset)
      not Paciente.Identification.rut?(appointment_params["rut_paciente"]) -&gt;
        conn
        |&gt; put_flash(:error, "RUT no es válido")
        |&gt; render("new.html", changeset: changeset)
      true -&gt;
        case Repo.insert(changeset) do
          {:ok, appointment} -&gt;
            conn
            |&gt; put_flash(:info, "Appointment created succesfully")
            |&gt; redirect(to: appointment_path(conn, :show, appointment))
          {:error, changeset} -&gt;
            render(conn, "new.html", changeset: changeset)
        end      
    end
  end  
</code></pre>
<p>Now a better version using as changeset validation</p>
<p>On your <code>Appointment</code> module you have the <code>changeset/2</code> function, the one you are using on your controller, there you add a pipe to <a href="https://hexdocs.pm/ecto/Ecto.Changeset.html#validate_change/3" rel="noopener nofollow ugc">validate_change</a></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def changeset(%Appointment{} = appointment, attrs \\ %{}) do
    appointment
    |&gt; cast([....]) # your fields here
    # |&gt; validate_length() ... some already present validations
    # add this, note that I consider the rut field as :rut_paciente
    |&gt; validate_change(:rut_paciente, fn :rut_paciente, rut_value -&gt;
      if Paciente.Identification.rut?(rut_value) do
        [:rut_paciente, "RUT no es válido"]
      else
        []
      end
    end)
  end
</code></pre>
<p>The <code>Paciente.Identification.rut?/1</code> function that perreynders implement will return true or false so is a very plugable function, whenever you need to check rut for true or false you can use it</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="84051" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-i-put-an-if-statement-in-a-templates-file-in-elixir-phoenix/14454/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-84051" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="84051"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #31"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/14454/load_more?page=4">Load more posts (4 remaining)</a>
</div></template></turbo-stream>