-
-
Save rmoorman/dfdf5c2493144edf62aa18c651a49054 to your computer and use it in GitHub Desktop.
Simple shot at implementing an email validator for use with `Ecto.Changeset`
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 characters
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