validator_base_length (zotonic_mod_base v1.0.0-rc.17)

Check the length of a text input.

Test if the length of the input’s value is more than a minimum and/or less than a maximum length.

Arguments are minimum and maximum. You can give either or both arguments.

For example, a summary that is neither too long nor too short:

<textarea id="summary" name="summary"></textarea>
{% validate id="summary" type={length minimum=20 maximum=200} %}

Arguments

ArgumentDescriptionExample
isUse when the value must be a specific length.is=4
minimumThe minimum length of the value.minimum=4
maximumThe maximum length of the value.maximum=10
wrong\_length\_messageMessage for when the length is unequal to the value of the “is” argument. Defaults to “Must be . characters long.”
too\_short\_messageMessage for when there are not enough characters entered. Defaults to “Must not be less than . characters long.”
too\_long\_messageMessage for when there are too many characters entered. Defaults to “Must not be more than . characters long.”

See also

Forms and validation

Summary

Functions

render_validator/5

validate/5

-spec validate(term(), term(), term(), list(), z:context()) ->
                  {{ok, term()}, z:context()} | {{error, term(), term()}, z:context()}.