Back to Validation

StartsWith

docs/validators/StartsWith.md

3.1.12.6 KB
Original Source
<!-- SPDX-License-Identifier: MIT SPDX-FileCopyrightText: (c) Respect Project Contributors SPDX-FileContributor: Alexandre Gomes Gaigalas <[email protected]> SPDX-FileContributor: Danilo Correa <[email protected]> SPDX-FileContributor: Henrique Moody <[email protected]> -->

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:

php
v::startsWith('lorem')->assert('lorem ipsum');
// Validation passes successfully

v::startsWith('Dr.', 'Mr.')->assert('Dr. Jane Doe');
// Validation passes successfully

For arrays:

php
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

ModeTemplate
default{{subject}} must start with {{startValue}}
inverted{{subject}} must not start with {{startValue}}

StartsWith::TEMPLATE_MULTIPLE_VALUES

ModeTemplate
default{{subject}} must start with {{startValues|list:or}}
inverted{{subject}} must not start with {{startValues|list:or}}

Template placeholders

PlaceholderDescription
subjectThe validated input or the custom validator name (if specified).
startValueThe value that will be checked to be at the start of the input.
startValuesAdditional values to check.

Categorization

  • Arrays
  • Strings

Changelog

VersionDescription
3.1.0Added support for multiple values
3.0.0Case-insensitive comparison removed
0.3.9Created

See Also