Last active
March 27, 2023 17:42
-
-
Save mgamini/4f3a8bc55bdcc96be2c6 to your computer and use it in GitHub Desktop.
Revisions
-
mgamini revised this gist
Jan 27, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ # 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] -> -
mgamini created this gist
Aug 16, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ defmodule EmailValidator do # ensure that the email looks valid def validate_email(email) when is_binary(email) do case Regex.run(~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/, email) do nil -> {:error, "Invalid email"} [email] -> try do Regex.run(~r/(\w+)@([\w.]+)/, email) |> validate_email rescue _ -> {:error, "Invalid email"} end end end # check the email against a list of accepted domains, then make check if it is unique def validate_email([email, username, host]) do case host in Config.accepted_domains do true -> case find_by_email(email) do nil -> :ok _account -> :account end _ -> {:error, "Not an accepted domain."} end end end