greaterThan validator

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

Options

Using with form field
The HTML attributes are used to set the validator options via the Declarative plugin
(* denotes a required option)
NameHTML attributeTypeDescription
inclusivedata-fv-greater-than___inclusiveBooleanCan 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.
messagedata-fv-greater-than___messageStringThe error message
min *data-fv-greater-than___minFloatThe 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.
Using the ES6 module
// You might need to change the importing path
import { greaterThan } from '/vendors/@form-validation/cjs/validator-greater-than';
const result = greaterThan().validate({
value: ...,
options: {
inclusive: ...,
message: ...,
min: ...,
},
});
/*
result is an object of
{
valid: true or false,
message: The error message
}
*/
Using the npm package
  • Install the validator package:
$ npm install @form-validation/validator-greater-than
  • Use the greaterThan validator:
import { greaterThan } from '@form-validation/validator-greater-than';
const result = greaterThan().validate({
value: ...,
options: {
inclusive: ...,
message: ...,
min: ...,
},
});

Basic example

greaterThan validator

NPM package example

The following snippet shows how to use the greaterThan validator with the npm package:
import { greaterThan } from '@form-validation/validator-greater-than';
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

See also

Changelog

v2.1.0
  • The validator doesn't work properly if the message property isn't defined
v2.0.0
  • Add the npm package
v1.6.0
  • Fixed an issue that the min option isn't passed to the placeholder message