Funx.Validator.Confirmation (funx v0.8.2)

View Source

Validates that a value matches another field in the data structure.

Useful for password confirmation, email confirmation, etc.

Required Options

  • :field – The field name to compare against (atom)
  • :data – The full data structure containing both fields

Optional Options

  • :eq – An equality comparator. Defaults to Funx.Eq.Protocol.
  • :message – Custom error message callback (value -> String.t())

Examples

iex> data = %{password: "secret", password_confirmation: "secret"}
iex> Funx.Validator.Confirmation.validate("secret", field: :password, data: data)
%Funx.Monad.Either.Right{right: "secret"}

iex> data = %{password: "secret", password_confirmation: "wrong"}
iex> Funx.Validator.Confirmation.validate("wrong", field: :password, data: data)
%Funx.Monad.Either.Left{
  left: %Funx.Errors.ValidationError{errors: ["does not match password"]}
}

Summary

Functions

validate(value)

validate(value, opts)