respect-validation/docs/Length.md
Henrique Moody 2a2e1d577e
Change how documentation of rules are presented
Rules are not always used from the alias `v`, neither called staticaly.
2017-03-27 17:26:21 +02:00

904 B

Length

  • Length(int $min, int $max)
  • Length(int $min, null)
  • Length(null, int $max)
  • Length(int $min, int $max, bool $inclusive)

Validates lengths. Most simple example:

v::stringType()->length(1, 5)->validate('abc'); // true

You can also validate only minimum length:

v::stringType()->length(5, null)->validate('abcdef'); // true

Only maximum length:

v::stringType()->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::arrayVal()->length(1, 5)->validate(['foo', 'bar']); // true

A third parameter may be passed to validate the passed values inclusive:

v::stringType()->length(1, 5, true)->validate('a'); // true

Message template for this validator includes {{minValue}} and {{maxValue}}.


See also: