mirror of
https://github.com/Respect/Validation.git
synced 2026-03-14 22:35:45 +01:00
This commit introduces the `Trimmed` validator that ensures a string cannot start or end with a list of specific values. The default values used are a selected list of Unicode invisible characters. To support this change, the StartsWith and EndsWith validators were modified so they can also support multiple values to check for. While StartsWith and EndsWith are more generic, and also perform start-of-array and end-of-array kinds of checks, Trimmed is more focused on string inputs, which tailors to a more specific use case.
2.6 KiB
2.6 KiB
StartsWith
StartsWith(mixed $startValue)StartsWith(mixed $startValue, mixed ...$startValues)
Validates whether the input starts with one of the given values.
This validator is similar to Contains, but validates only if the value is at the beginning of the input.
For strings:
v::startsWith('lorem')->assert('lorem ipsum');
// Validation passes successfully
v::startsWith('Dr.', 'Mr.')->assert('Dr. Jane Doe');
// Validation passes successfully
For arrays:
v::startsWith('lorem')->assert(['lorem', 'ipsum']);
// Validation passes successfully
v::startsWith(0, 1)->assert([0, 1, 2, 3]);
// Validation passes successfully
v::startsWith(0, 1)->assert([1, 2, 3]);
// Validation passes successfully
Message template for this validator includes {{startValue}} and {{startValues}}.
Templates
StartsWith::TEMPLATE_STANDARD
| Mode | Template |
|---|---|
default |
{{subject}} must start with {{startValue}} |
inverted |
{{subject}} must not start with {{startValue}} |
StartsWith::TEMPLATE_MULTIPLE_VALUES
| Mode | Template |
|---|---|
default |
{{subject}} must start with {{startValues|list:or}} |
inverted |
{{subject}} must not start with {{startValues|list:or}} |
Template placeholders
| Placeholder | Description |
|---|---|
subject |
The validated input or the custom validator name (if specified). |
startValue |
The value that will be checked to be at the start of the input. |
startValues |
Additional values to check. |
Categorization
- Arrays
- Strings
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Added support for multiple values |
| 3.0.0 | Case-insensitive comparison removed |
| 0.3.9 | Created |