Skip to content

Instantly share code, notes, and snippets.

@wttj-tech
Created March 28, 2022 08:36
Show Gist options
  • Save wttj-tech/5cc64eb737034361e83c55f1f5ea3d3a to your computer and use it in GitHub Desktop.
Save wttj-tech/5cc64eb737034361e83c55f1f5ea3d3a to your computer and use it in GitHub Desktop.
Password validations
defmodule User do
def changeset(user, attrs) do
user
|> cast(attrs, [:password])
|> validate_length(:password, min: 12)
|> validate_format(:password, ~r/[a-z]/, message: "at least one lower case character")
|> validate_format(:password, ~r/[A-Z]/, message: "at least one upper case character")
|> validate_format(:password, ~r/[!?@#$%^&*_0-9]/, message: "at least one digit or punctuation character")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment