Funx.Validator.MaxLength (funx v0.8.2)

View Source

Validates that a string does not exceed a maximum length.

Required Options

  • :max - Maximum length (integer)

Optional Options

  • :message - Custom error message callback (value -> String.t())

Examples

iex> Funx.Validator.MaxLength.validate("hi", [max: 5])
%Funx.Monad.Either.Right{right: "hi"}

iex> Funx.Validator.MaxLength.validate("hello world", [max: 5])
%Funx.Monad.Either.Left{left: %Funx.Errors.ValidationError{errors: ["must be at most 5 characters"]}}

iex> Funx.Validator.MaxLength.validate("hello world", [max: 5, message: fn val -> "'#{val}' is too long" end])
%Funx.Monad.Either.Left{left: %Funx.Errors.ValidationError{errors: ["'hello world' is too long"]}}

Summary

Functions

validate(value)

validate(value, opts)