respect-validation/docs/rules/Length.md

54 lines
1,019 B
Markdown
Raw Permalink Normal View History

2015-01-30 09:40:06 +01:00
# Length
- `Length(int $min, int $max)`
- `Length(int $min, null)`
- `Length(null, int $max)`
- `Length(int $min, int $max, bool $inclusive)`
2015-01-30 09:40:06 +01:00
Validates the length of the given input.
Most simple example:
2015-01-30 09:40:06 +01:00
```php
v::stringType()->length(1, 5)->validate('abc'); // true
2015-01-30 09:40:06 +01:00
```
You can also validate only minimum length:
```php
2015-10-07 16:52:03 +02:00
v::stringType()->length(5, null)->validate('abcdef'); // true
2015-01-30 09:40:06 +01:00
```
Only maximum length:
```php
2015-10-07 16:52:03 +02:00
v::stringType()->length(null, 5)->validate('abc'); // true
2015-01-30 09:40:06 +01:00
```
The type as the first validator in a chain is a good practice,
since length accepts many types:
```php
v::arrayVal()->length(1, 5)->validate(['foo', 'bar']); // true
2015-01-30 09:40:06 +01:00
```
A third parameter may be passed to validate the passed values inclusive:
```php
v::stringType()->length(1, 5, true)->validate('a'); // true
2015-01-30 09:40:06 +01:00
```
Message template for this validator includes `{{minValue}}` and `{{maxValue}}`.
## Changelog
Version | Description
--------|-------------
0.3.9 | Created
***
2015-01-30 09:40:06 +01:00
See also:
- [Between](Between.md)
2018-12-11 13:31:50 +01:00
- [Min](Min.md)