Skip to content

Instantly share code, notes, and snippets.

@daemonfire300
Created October 13, 2016 12:07
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daemonfire300/b6705a9ce103a8bf3f70c755350ac683 to your computer and use it in GitHub Desktop.
Save daemonfire300/b6705a9ce103a8bf3f70c755350ac683 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