Skip to content

Instantly share code, notes, and snippets.

@amandasposito
Created September 3, 2016 14:04
Show Gist options
  • Save amandasposito/a52e61e6d4f9cbf55cfdc9cef1f7f1b1 to your computer and use it in GitHub Desktop.
Save amandasposito/a52e61e6d4f9cbf55cfdc9cef1f7f1b1 to your computer and use it in GitHub Desktop.
def changeset(user, params \\ %{}) do
user
|> cast(params, [:name, :email, :age])
|> validate_required([:name, :email])
|> validate_format(:email, ~r/@/)
|> validate_inclusion(:age, 18..100)
|> unique_constraint(:email)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment