respect-validation/docs/rules/ContainsAny.md
Henrique Moody 48405271c5
Replace placeholder "name" with "subject"
The `{{name}}` placeholder could represent different things depending on
the state of the Result, and referring to it as `{{name}}` seems
arbitrary. This commit changes it to `{{subject}}`, which is much more
generic and it describes well what that placeholder can mean.
2025-12-26 21:30:01 +01:00

59 lines
1.5 KiB
Markdown

# ContainsAny
- `ContainsAny(array $needles)`
- `ContainsAny(array $needles, bool $identical)`
Validates if the input contains at least one of defined values
For strings (comparing is case insensitive):
```php
v::containsAny(['lorem', 'dolor'])->isValid('lorem ipsum'); // true
```
For arrays (comparing is case sensitive to respect "contains" behavior):
```php
v::containsAny(['lorem', 'dolor'])->isValid(['ipsum', 'lorem']); // true
```
A second parameter may be passed for identical comparison instead
of equal comparison for arrays.
Message template for this validator includes `{{needles}}`.
## Templates
### `ContainsAny::TEMPLATE_STANDARD`
| Mode | Template |
| ---------- | ------------------------------------------------------------ |
| `default` | {{subject}} must contain at least one value from {{needles}} |
| `inverted` | {{subject}} must not contain any value from {{needles}} |
## Template placeholders
| Placeholder | Description |
| ----------- | ---------------------------------------------------------------- |
| `subject` | The validated input or the custom validator name (if specified). |
| `needles` | |
## Categorization
- Arrays
- Strings
## Changelog
| Version | Description |
| ------: | ----------- |
| 2.0.0 | Created |
---
See also:
- [AnyOf](AnyOf.md)
- [Contains](Contains.md)
- [Equivalent](Equivalent.md)
- [In](In.md)