Back to Validation

AnyOf

docs/validators/AnyOf.md

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

AnyOf

  • AnyOf(Validator $validator1, Validator $validator2)
  • AnyOf(Validator $validator1, Validator $validator2, Validator ...$validators)

This is a group validator that acts as an OR operator.

php
v::anyOf(v::intVal(), v::floatVal())->assert(15.5);
// Validation passes successfully

In the sample above, IntVal() doesn't validates, but FloatVal() validates, so AnyOf() returns true.

AnyOf() returns true if at least one inner validator passes.

Templates

AnyOf::TEMPLATE_STANDARD

ModeTemplate
default{{subject}} must pass at least one of the rules
inverted{{subject}} must pass at least one of the rules

Template placeholders

PlaceholderDescription
subjectThe validated input or the custom validator name (if specified).

Categorization

  • Composite
  • Nesting

Changelog

VersionDescription
3.0.0Require at least two validators to be defined
2.0.0Created

See Also