EndsWith(mixed $endValue)EndsWith(mixed $endValue, mixed ...$endValues)
This validator is similar to Contains(), but validates
only if one of the values is at the end of the input. Only
string inputs and string end values are checked; non‑string
values are considered invalid but will not produce PHP errors
thanks to internal type guards.
For strings (non-string inputs are always rejected):
v::endsWith('ipsum')->assert('lorem ipsum');
// Validation passes successfully
v::endsWith(', PhD', ', doctor')->assert('Jane Doe, PhD');
// Validation passes successfullyFor arrays:
v::endsWith('ipsum')->assert(['lorem', 'ipsum']);
// Validation passes successfully
v::endsWith('.', ';')->assert(['this', 'is', 'a', 'tokenized', 'phrase', '.']);
// Validation passes successfully
v::endsWith('.', ';')->assert(['this', 'is', 'a', 'tokenized', 'phrase']);
// → `["this", "is", "a", "tokenized", "phrase"]` must end with "." or ";"Message template for this validator includes {{endValue}} and {{endValues}}.
| Mode | Template |
|---|---|
default |
{{subject}} must end with {{endValue}} |
inverted |
{{subject}} must not end with {{endValue}} |
| Mode | Template |
|---|---|
default |
{{subject}} must end with {{endValues|list:or}} |
inverted |
{{subject}} must not end with {{endValues|list:or}} |
| Placeholder | Description |
|---|---|
subject |
The validated input or the custom validator name (if specified). |
endValue |
The value that will be checked to be at the end of the input. |
endValues |
Additional values to check. |
- Arrays
- Strings
| Version | Description |
|---|---|
| 3.1.0 | Added support for multiple values |
| 3.0.0 | Case-insensitive comparison removed |
| 0.3.9 | Created |