mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
907 B
907 B
Length
v::length(int $min, int $max)v::length(int $min, null)v::length(null, int $max)v::length(int $min, int $max, boolean $inclusive = true)
Validates lengths. Most simple example:
v::string()->length(1, 5)->validate('abc'); //true
You can also validate only minimum length:
v::string()->length(5, null)->validate('abcdef'); // true
Only maximum length:
v::string()->length(null, 5)->validate('abc'); // true
The type as the first validator in a chain is a good practice, since length accepts many types:
v::arr()->length(1, 5)->validate(array('foo', 'bar')); //true
A third parameter may be passed to validate the passed values inclusive:
v::string()->length(1, 5, true)->validate('a'); //true
Message template for this validator includes {{minValue}} and {{maxValue}}.
See also: