Ecto.Changeset.validate_confirmation

You're seeing just the function validate_confirmation, go back to Ecto.Changeset module for more information.
Link to this function

validate_confirmation(changeset, field, opts \\ [])

View Source

Specs

validate_confirmation(t(), atom(), Keyword.t()) :: t()

Validates that the given parameter matches its confirmation.

By calling validate_confirmation(changeset, :email), this validation will check if both "email" and "email_confirmation" in the parameter map matches. Note this validation only looks at the parameters themselves, never the fields in the schema. As such as, the "email_confirmation" field does not need to be added as a virtual field in your schema.

Note that if the confirmation field is nil or missing, this does not add a validation error. You can specify that the confirmation parameter is required in the options (see below).

Options

  • :message - the message on failure, defaults to "does not match confirmation"
  • :required - boolean, sets whether existence of confirmation parameter is required for addition of error. Defaults to false

Examples

validate_confirmation(changeset, :email)
validate_confirmation(changeset, :password, message: "does not match password")

cast(data, params, [:password])
|> validate_confirmation(:password, message: "does not match password")