greaterThan validator

Check if the value is greater than or equals to given number

Options

Use with form field

* presents a required option. The HTML attributes are used to set the validator options via the Declarative plugin

Name HTML attribute Type Description
inclusive data-fv-greater-than___inclusive Boolean Can be true (default) or false.
If true, the input value must be greater than or equal to the comparison one.
If false, the input value must be greater than the comparison one.
message data-fv-greater-than___message String The error message
min* data-fv-greater-than___min Float The number to make a comparison to

If you want the value to support custom format, such as a comma for thousand separator, you should use the Transformer plugin.

Use with JavaScript module


// You might need to change the importing path
import greaterThan from 'formvalidation/validators/greaterThan';

const result = greaterThan().validate({
    value: ...,
    options: {
        inclusive: ...,
        message: ...,
        min: ...,
    },
});
/*
result is an object of
{
    valid: true or false,
    message: The error message
}
*/

Basic Example

Module Example

The following snippet shows how to use the greaterThan validator with JavaScript module:


// You might need to change the importing path
import greaterThan from 'formvalidation/validators/greaterThan';

const res1 = greaterThan().validate({
    value: 20,
    options: {
        message: 'The value has to be greater than 18',
        min: 18,
    },
});
// res1.valid === true

const res2 = greaterThan().validate({
    value: 18,
    options: {
        inclusive: false,
        message: 'The value has to be greater than 18',
        min: 18,
    },
});
// res2.valid === false

Related validators

The following validators are similar to this one and might be useful to you.

Name Description
between Check if the input value is between (strictly or not) two given numbers
lessThan Check if the value is less than or equals to given number