DValidate.ValidateLength (d_validate v1.1.0)
Summary
Functions
Validates if a value has a length within a specified range or an exact length.
Functions
Link to this function
call(field_name, value, opts)
Validates if a value has a length within a specified range or an exact length.
Parameters
field_name: The name of the field being validated (atom).value: The value whose length is being checked (string).opts: Keyword list for validation options. Can be one of:minandmaxfor range validation.lengthfor exact length validation.
Return values
:okif the length ofvalueis within the specified range or matches the exact length.{:error, field_name, "is too short"}if the length is less thanminorlength.{:error, field_name, "is too long"}if the length is greater thanmaxorlength.
Examples
iex> DValidate.ValidateLength.call(:field_name, "abc", min: 1, max: 3)
:ok
iex> DValidate.ValidateLength.call(:field_name, "a", min: 2, max: 5)
{:error, :field_name, "is too short"}
iex> DValidate.ValidateLength.call(:field_name, "abcdef", min: 1, max: 5)
{:error, :field_name, "is too long"}
iex> DValidate.ValidateLength.call(:field_name, "abc", length: 3)
:ok
iex> DValidate.ValidateLength.call(:field_name, "a", length: 5)
{:error, :field_name, "is too short"}
iex> DValidate.ValidateLength.call(:field_name, "abcdef", length: 5)
{:error, :field_name, "is too long"}