validator_base_numericality (zotonic_mod_base v1.0.0-rc.17)

Numerical input and range check.

Checks if the input is a number and within a certain range or equal to a fixed value. At the moment only integer inputs are allowed.

Arguments are is, minimum and maximum.

For example, when the input must be 42:

<input type="text" id="number" name="number" value="" />
{% validate id="number" type={numericality is=42} %}

And for a number within a certain range:

<input type="text" id="percent" name="percent" value="" />
{% validate id="percent" type={numericality minimum=0 maximum=100} %}

Arguments

ArgumentDescriptionExample
isTests for equality.is=42
minimumMinimum value.minimum=1
maximumMaximum value.maximum=100
is\_floatBoolean flag which tells if the input can be a floating point number. Defaults to false.is_float is_float=true
not\_a\_number\_messageMessage to show when the entered value is not a number. Defaults to “Must be a number.”not_a_number_message="*"
not\_an\_integer\_messageMessage to show when the entered number is not an integer. Defaults to “Must be an integer.”
wrong\_number\_messageMessage to show when the entered number is unequal to the .is. argument. Defaults to “Must be ..”
too\_low\_messageMessage for when the entered number is less than the minimum allowed. Defaults to “Must not be less than ..”
too\_high\_messageMessage for when the entered number is greater than the maximum allowed. Defaults to “Must not be more than ..”

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()}.