View Source Draft.Validator.Exclusion (Draft v1.0.2)

Ensure a value is not a member of a list of values.

options

Options

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

The list can be provided in place of the keyword list if no other options are needed.

examples

Examples

iex> Draft.Validator.Exclusion.validate(1, [1, 2, 3])
{:error, "must not be one of [1, 2, 3]"}

iex> Draft.Validator.Exclusion.validate(1, [in: [1, 2, 3]])
{:error, "must not be one of [1, 2, 3]"}

iex> Draft.Validator.Exclusion.validate(1, [in: [1, 2, 3], message: "<%= value %> shouldn't be in <%= inspect list %>"])
{:error, "1 shouldn't be in [1, 2, 3]"}

iex> Draft.Validator.Exclusion.validate(4, [1, 2, 3])
{:ok, 4}

iex> Draft.Validator.Exclusion.validate("a", ~w(a b c))
{:error, ~S(must not be one of ["a", "b", "c"])}

iex> Draft.Validator.Exclusion.validate("a", in: ~w(a b c), message: "must not be abc, talkin' 'bout 123")
{:error, "must not be abc, talkin' 'bout 123"}

Link to this section Summary

Functions

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

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

Link to this section Functions

Link to this function

validate(value, options)

View Source

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

Link to this function

validate(data, context, options)

View Source

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