Skip to content

Instantly share code, notes, and snippets.

@rmoorman
Forked from daemonfire300/email.exs
Created November 20, 2021 12:42
Show Gist options
  • Save rmoorman/dfdf5c2493144edf62aa18c651a49054 to your computer and use it in GitHub Desktop.
Save rmoorman/dfdf5c2493144edf62aa18c651a49054 to your computer and use it in GitHub Desktop.
Simple shot at implementing an email validator for use with `Ecto.Changeset`
defmodule YourApp.Validators.Email do
use Ecto.Changeset
@mail_regex ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
# ensure that the email looks valid
def validate_email(changeset, field) do
changeset
|> validate_format(field, @mail_regex)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment