Vex.Validators.Presence (Vex v0.9.2) View Source
Ensure a value is present.
Vex uses the Vex.Blank
protocol to determine "presence."
Notably, empty strings and collections are not considered present.
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.Presence.validate(1, true)
:ok
iex> Vex.Validators.Presence.validate(nil, true)
{:error, "must be present"}
iex> Vex.Validators.Presence.validate(false, true)
{:error, "must be present"}
iex> Vex.Validators.Presence.validate("", true)
{:error, "must be present"}
iex> Vex.Validators.Presence.validate([], true)
{:error, "must be present"}
iex> Vex.Validators.Presence.validate([], true)
{:error, "must be present"}
iex> Vex.Validators.Presence.validate([1], true)
:ok
iex> Vex.Validators.Presence.validate({1}, true)
:ok
Custom Error Messages
Custom error messages (in EEx format), provided as :message, can use the following values:
iex> Vex.Validators.Presence.__validator__(:message_fields)
[value: "The bad value"]
An example:
iex> Vex.Validators.Presence.validate([], message: "needs to be more sizable than <%= inspect value %>")
{:error, "needs to be more sizable than []"}
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
Callback implementation for c:Vex.Validator.Behaviour.validate/2
.
Callback implementation for c:Vex.Validator.Behaviour.validate/3
.