Length(Validator $validator)
Validates the length of the given input against a given validator.
v::length(v::between(1, 5))->assert('abc');
// Validation passes successfully
v::length(v::greaterThan(5))->assert('abcdef');
// Validation passes successfully
v::length(v::lessThan(5))->assert('abc');
// Validation passes successfullyThis validator can be used to validate the length of strings, arrays, and objects that implement the Countable interface.
v::length(v::greaterThanOrEqual(3))->assert([1, 2, 3]);
// Validation passes successfully
v::length(v::equals(0))->assert(new SplPriorityQueue());
// Validation passes successfullyUsed when it's possible to get the length of the input.
| Mode | Template |
|---|---|
default |
The length of |
inverted |
The length of |
| Mode | Template |
|---|---|
default |
{{subject}} must be countable or a string |
inverted |
{{subject}} must not be countable or a string |
The template serves as a prefix to the template of the inner validator.
v::length(v::equals(3))->assert('tulip');
// → The length of "tulip" must be equal to 3
v::not(v::length(v::equals(4)))->assert('rose');
// → The length of "rose" must not be equal to 4Used when it's impossible to get the length of the input.
| Mode | Template |
|---|---|
default |
{{subject}} must be a countable value or a string |
inverted |
{{subject}} must not be a countable value or a string |
| Placeholder | Description |
|---|---|
subject |
The validated input or the custom validator name (if specified). |
- Comparisons
- Transformations
| Version | Description |
|---|---|
| 3.0.0 | Became a transformation |
| 0.3.9 | Created |