Created
October 13, 2016 12:07
-
-
Save daemonfire300/b6705a9ce103a8bf3f70c755350ac683 to your computer and use it in GitHub Desktop.
Simple shot at implementing an email validator for use with `Ecto.Changeset`
This file contains 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