Funx.Validator.MaxLength (funx v0.8.0)
View SourceValidates 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"]}}