justify v0.1.2 Justify
Link to this section Summary
Functions
Adds an error to the dataset
Validates the given field is true
Validates that the given field matches the confirmation value for that field
Validates a field’s value is not included in the given enumerable
Validates that a field’s value is of the given format
Validates a field’s value is included in the given enumerable
Validates a field’s value is a string or list of the given length
Validates that one or more fields are present in the dataset
Link to this section Functions
add_error(Justify.Dataset.t(), atom(), String.t(), Keyword.t()) :: Justify.Dataset.t()
Adds an error to the dataset.
An additional keyword list can be passed to provide additional contextual information for the error.
validate_acceptance(Justify.Dataset.t() | map() | struct(), atom(), Keyword.t()) :: Justify.Dataset.t()
Validates the given field is true
.
Options
:message
- the message on failure, defaults to “must be accepted”
validate_confirmation(Justify.Dataset.t() | map() | struct(), atom(), Keyword.t()) :: Justify.Dataset.t()
Validates that the given field matches the confirmation value for that field.
By default, the field will be checked against a field with the same name
appended with _confirmation
(e.g. :email
would be checked against
:email_confirmation
). It’s possible to provide a custom field by providing
a value to the :confirmation_field
option.
Note that if the confirmation field is nil
or missing, by default an error
will not be added. You can specify that the confirmation field is required in
the options (see below). Note, the confirmation field does not need to be
added to structs.
Options
:confirmation_field
- the field to check against:message
- the message on failure, defaults to “does not match”:required
- sets whether existence of a confirmation field is required
validate_exclusion(Justify.Dataset.t() | map() | struct(), atom(), Enum.t(), Keyword.t()) :: Justify.Dataset.t()
Validates a field’s value is not included in the given enumerable.
Options
:message
- the message on failure, defaults to “is reserved”
validate_format(Justify.Dataset.t() | map() | struct(), atom(), Regex.t(), Keyword.t()) :: Justify.Dataset.t()
Validates that a field’s value is of the given format.
The format must be expressed as a regular expression.
Options
:message
- the message on failure, defaults to “has invalid format”
validate_inclusion(Justify.Dataset.t() | map() | struct(), atom(), Enum.t(), Keyword.t()) :: Justify.Dataset.t()
Validates a field’s value is included in the given enumerable.
Options
:message
- the message on failure, defaults to “is invalid”
validate_length(Justify.Dataset.t() | map() | struct(), atom(), Keyword.t()) :: Justify.Dataset.t()
Validates a field’s value is a string or list of the given length.
If a binary’s length is 0 an error will not be added. nil
values are
considered to have a length of 0. If you need to check for empty strings or
nil
values use validate_required/3
.
Options
:is
- the length must be exactly this value:min
- the length must be greater than or equal to this value:max
- the length must be less than or equal to this value:count
- what length to count for string,:graphemes
(default) or:codepoints
:message
- the message on failure, depending on the value type, is one offor strings
- “should be %{count} character(s)”
- “should be at least %{count} character(s)”
- “should be at most %{count} character(s)”
for lists
- “should have %{count} item(s)”
- “should have at least %{count} item(s)”
- “should have at most %{count} item(s)”
validate_required(Justify.Dataset.t() | map() | struct(), list() | atom(), Keyword.t()) :: Justify.Dataset.t()
Validates that one or more fields are present in the dataset.
If the value of a field is nil
or a string made only of whitespace, the
dataset is marked as invalid.
If a field does not exist within the dataset, the dataset is marked as invalid.
Options
:message
- the message on failure, defaults to “can’t be blank”