min
The
min
validator checks that a numeric value is at least the minimum value provided.If the value being validated is
null
, false
, an empty string, or another falsy value other than 0
, then the result will be valid. This respects the rule of thumb described in the notes for the required validator.min
: The minimum value compared against
The
min
validator supports three parameter signatures:- 1.
min(value)
where the value is used as themin
named prop - 2.
min(propsObject)
where the props object contains amin
named prop - 3.
min(propsFunction)
where the props function returns a props object with amin
named prop
import validate, {min} from 'strickland';
// As a value parameter
const minOf3 = min(3);
// As a named prop
const minOf2 = min({
min: 2,
message: 'Must be at least 2'}
);
// As a function that resolves to have the named prop
const minValidator = min((context) => ({
min: context.min,
message: `Must be at least ${context.min}`
}));
Last modified 2yr ago