Vex.Validators.Confirmation (Vex v0.9.2) View Source

Ensure a value, if provided, is equivalent to a second value.

Generally used to check, eg, a password and password confirmation.

Note: This validator is treated differently by Vex, in that two values are passed to it.

Options

  • :message: Optional. A custom error message. May be in EEx format and use the fields described in "Custom Error Messages," below.

Examples

iex> Vex.Validators.Confirmation.validate(["foo", "bar"], true)
{:error, "must match its confirmation"}
iex> Vex.Validators.Confirmation.validate(["foo", "foo"], true)
:ok
iex> Vex.Validators.Confirmation.validate(["foo", "bar"], message: "<%= confirmation %> isn't the same as <%= value %>!")
{:error, "bar isn't the same as foo!"}
iex> Vex.Validators.Confirmation.validate([nil, "bar"], true)
:ok
iex> Vex.Validators.Confirmation.validate(["foo", nil], true)
{:error, "must match its confirmation"}
iex> Vex.Validators.Confirmation.validate(["foo", nil], message: "must match!")
{:error, "must match!"}
iex> Vex.Validators.Confirmation.validate(["", "unneeded"], [allow_blank: true])
:ok

Custom Error Messages

Custom error messages (in EEx format), provided as :message, can use the following values:

iex> Vex.Validators.Confirmation.__validator__(:message_fields)
[value: "The value to confirm", confirmation: "Bad confirmation value"]

An example:

iex> Vex.Validators.Confirmation.validate(["foo", nil], message: "<%= inspect confirmation %> doesn't match <%= inspect value %>")
{:error, ~S(nil doesn't match "foo")}

Link to this section Summary

Functions

Callback implementation for c:Vex.Validator.Behaviour.validate/2.

Callback implementation for c:Vex.Validator.Behaviour.validate/3.

Link to this section Functions

Link to this function

validate(values, options)

View Source

Callback implementation for c:Vex.Validator.Behaviour.validate/2.

Link to this function

validate(data, context, options)

View Source

Callback implementation for c:Vex.Validator.Behaviour.validate/3.