Funx.Validator.Confirmation (funx v0.8.2)
View SourceValidates 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 toFunx.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"]}
}