Skip to content

Instantly share code, notes, and snippets.

View mgamini's full-sized avatar

Garrett Amini mgamini

View GitHub Profile
@mgamini
mgamini / Elixir Email Validation
Last active March 27, 2023 17:42
Elixir Email Validation
defmodule EmailValidator do
# ensure that the email looks valid
def validate_email(email) when is_binary(email) do
case Regex.run(~r/^[\w.!#$%&’*+\-\/=?\^`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/i, email) do
nil ->
{:error, "Invalid email"}
[email] ->
try do
Regex.run(~r/(\w+)@([\w.]+)/, email) |> validate_email