respect-validation/docs/validators.md
Alexandre Gomes Gaigalas bcc60ec035 Allow empty values in iterables for All, Each, Max, Min
Now empty values are again allowed in FilteredArray-style
validators.

To solve the issue with negation, a Result attribute was
added to signal indeciseveness (when a result cannot be
reliably inverted). On such cases, we consider that result
to be valid.

For example, `v::not(v::min(v::equals(10)))` says "The
lowest value of the iterable input should not be equal 10".

If the input is empty, we cannot decide whether its minimum
is equal to 10 or not, so the validator essentially becomes
a null-op.

Users that want to ensure these validators have a valid
decidable target must use it in combination with `Length`
or other similar validators to achieve the same result.
2026-01-30 21:27:16 +00:00

27 KiB

Validators

In this page you will find a list of validators by their category.

Arrays: ArrayType - ArrayVal - Contains - ContainsAny - ContainsCount - Each - EndsWith - In - Key - KeyExists - KeyOptional - KeySet - Sorted - StartsWith - Subset - Unique

Banking: CreditCard - Iban

Booleans: AlwaysInvalid - AlwaysValid - BoolType - BoolVal - FalseVal - TrueVal

Callables: Call - CallableType - Callback - Lazy

Comparisons: All - Between - BetweenExclusive - Equals - Equivalent - GreaterThan - GreaterThanOrEqual - Identical - In - Length - LessThan - LessThanOrEqual - Max - Min

Composite: AllOf - AnyOf - Circuit - NoneOf - OneOf

Conditions: Circuit - Not - When

Core: Named - Not - Templated

Date and Time: Date - DateTime - DateTimeDiff - LeapDate - LeapYear - Time

Display: Masked - Named - Templated

File system: Directory - Executable - Exists - Extension - File - Image - Mimetype - Readable - Size - SymbolicLink - Writable

ISO codes: CountryCode - CurrencyCode - LanguageCode - SubdivisionCode

Identifications: Bsn - Cnh - Cnpj - Cpf - Hetu - Imei - Isbn - Luhn - MacAddress - NfeAccessKey - Nif - Nip - Pesel - Pis - PolishIdCard - PortugueseNif

Internet: Domain - Email - Ip - PublicDomainSuffix - Tld - Url

Localization: CountryCode - CurrencyCode - LanguageCode - PostalCode - SubdivisionCode

Math: Factor - Finite - Infinite - Multiple - Negative - Positive

Miscellaneous: Blank - Falsy - Masked - Named - Templated - Undef

Nesting: AllOf - AnyOf - Call - Circuit - Each - Key - KeySet - Lazy - NoneOf - Not - NullOr - OneOf - Property - PropertyOptional - UndefOr - When

Numbers: Base - Decimal - Digit - Even - Factor - Finite - FloatType - FloatVal - Infinite - IntType - IntVal - Multiple - Negative - Number - NumericVal - Odd - Positive - Roman

Objects: Attributes - Instance - ObjectType - Property - PropertyExists - PropertyOptional

Strings: Alnum - Alpha - Base64 - Charset - Consonant - Contains - ContainsAny - ContainsCount - Control - Digit - Emoji - EndsWith - Graph - HexRgbColor - In - Json - Lowercase - Phone - PostalCode - Printable - Punct - Regex - Slug - Sorted - Space - Spaced - StartsWith - StringType - StringVal - Uppercase - Uuid - Version - Vowel - Xdigit

Structures: Attributes - Key - KeyExists - KeyOptional - KeySet - Property - PropertyExists - PropertyOptional

Transformations: All - Call - Each - Length - Max - Min - Size

Types: ArrayType - ArrayVal - BoolType - BoolVal - CallableType - Countable - FloatType - FloatVal - IntType - IntVal - IterableType - IterableVal - NullType - NumericVal - ObjectType - ResourceType - ScalarVal - StringType - StringVal

Alphabetically

  • All - v::all(v::dateTime())->assert($releaseDates);
  • AllOf - v::allOf(v::intVal(), v::positive())->assert(15);
  • Alnum - v::alnum(' ')->assert('foo 123');
  • Alpha - v::alpha(' ')->assert('some name');
  • AlwaysInvalid - v::not(v::alwaysInvalid())->assert('whatever');
  • AlwaysValid - v::alwaysValid()->assert('whatever');
  • AnyOf - v::anyOf(v::intVal(), v::floatVal())->assert(15.5);
  • ArrayType - v::arrayType()->assert([]);
  • ArrayVal - v::arrayVal()->assert([]);
  • Attributes - v::attributes()->assert(new Person('John Doe', '2020-06-23', 'john.doe@gmail.com'));
  • Base - v::base(2)->assert('011010001');
  • Base64 - v::base64()->assert('cmVzcGVjdCE=');
  • Between - v::intVal()->between(10, 20)->assert(10);
  • BetweenExclusive - v::betweenExclusive('a', 'e')->assert('c');
  • Blank - v::blank()->assert(' ');
  • BoolType - v::boolType()->assert(true);
  • BoolVal - v::boolVal()->assert('on');
  • Bsn - v::bsn()->assert('612890053');
  • Call - v::call(str_split(...), v::arrayType()->lengthEquals(5))->assert('world');
  • CallableType - v::callableType()->assert(function () {});
  • Callback - v::callback(fn (int $input): bool => $input % 5 === 0,)->assert(10);
  • Charset - v::charset('ASCII')->assert('sugar');
  • Circuit - v::circuit(v::intVal(), v::floatVal())->assert(15);
  • Cnh - v::cnh()->assert('02650306461');
  • Cnpj - v::cnpj()->assert('00394460005887');
  • Consonant - v::consonant()->assert('xkcd');
  • Contains - v::contains('ipsum')->assert('lorem ipsum');
  • ContainsAny - v::containsAny(['lorem', 'dolor'])->assert('lorem ipsum');
  • ContainsCount - v::containsCount('ipsum', 2)->assert('ipsum lorem ipsum');
  • Control - v::control()->assert("\n\r\t");
  • Countable - v::countable()->assert([]);
  • CountryCode - v::countryCode()->assert('BR');
  • Cpf - v::cpf()->assert('95574461102');
  • CreditCard - v::creditCard()->assert('5376 7473 9720 8720');
  • CurrencyCode - v::currencyCode()->assert('GBP');
  • Date - v::date()->assert('2017-12-31');
  • DateTime - v::dateTime()->assert('2009-01-01');
  • DateTimeDiff - v::dateTimeDiff('years', v::greaterThan(18), 'd/m/Y')->assert('09/12/1990');
  • Decimal - v::decimal(2)->assert('27990.50');
  • Digit - v::digit(' ')->assert('020 612 1851');
  • Directory - v::directory()->assert(__DIR__);
  • Domain - v::domain()->assert('google.com');
  • Each - v::each(v::dateTime())->assert($releaseDates);
  • Email - v::email()->assert('alganet@gmail.com');
  • Emoji - v::emoji()->assert('🍕');
  • EndsWith - v::endsWith('ipsum')->assert('lorem ipsum');
  • Equals - v::equals('alganet')->assert('alganet');
  • Equivalent - v::equivalent(1)->assert(true);
  • Even - v::intVal()->even()->assert(2);
  • Executable - v::executable()->assert('/path/to/executable');
  • Exists - v::exists()->assert(__FILE__);
  • Extension - v::extension('png')->assert('image.png');
  • Factor - v::factor(0)->assert(5);
  • FalseVal - v::falseVal()->assert(false);
  • Falsy - v::falsy()->assert('');
  • File - v::file()->assert(__FILE__);
  • Finite - v::finite()->assert('10');
  • FloatType - v::floatType()->assert(1.5);
  • FloatVal - v::floatVal()->assert(1.5);
  • Graph - v::graph()->assert('LKM@#$%4;');
  • GreaterThan - v::greaterThan(10)->assert(11);
  • GreaterThanOrEqual - v::intVal()->greaterThanOrEqual(10)->assert(10);
  • Hetu - v::hetu()->assert('010106A9012');
  • HexRgbColor - v::hexRgbColor()->assert('#FFFAAA');
  • Iban - v::iban()->assert('SE35 5000 0000 0549 1000 0003');
  • Identical - v::identical(42)->assert(42);
  • Image - v::image()->assert('/path/to/image.gif');
  • Imei - v::imei()->assert('35-209900-176148-1');
  • In - v::in('lorem ipsum')->assert('ipsum');
  • Infinite - v::infinite()->assert(INF);
  • Instance - v::instance('DateTime')->assert(new DateTime);
  • IntType - v::intType()->assert(42);
  • IntVal - v::intVal()->assert('10');
  • Ip - v::ip()->assert('127.0.0.1');
  • Isbn - v::isbn()->assert('ISBN-13: 978-0-596-52068-7');
  • IterableType - v::iterableType()->assert([]);
  • IterableVal - v::iterableVal()->assert([]);
  • Json - v::json()->assert('{"foo":"bar"}');
  • Key - v::key('name', v::stringType())->assert(['name' => 'The Respect Panda']);
  • KeyExists - v::keyExists('name')->assert(['name' => 'The Respect Panda']);
  • KeyOptional - v::keyOptional('name', v::stringType())->assert([]);
  • KeySet - v::keySet(v::key('foo', v::intVal()))->assert(['foo' => 42]);
  • LanguageCode - v::languageCode()->assert('pt');
  • Lazy - v::lazy(static fn($input) => v::boolVal())->assert(true);
  • LeapDate - v::leapDate('Y-m-d')->assert('1988-02-29');
  • LeapYear - v::leapYear()->assert('1988');
  • Length - v::length(v::between(1, 5))->assert('abc');
  • LessThan - v::lessThan(10)->assert(9);
  • LessThanOrEqual - v::lessThanOrEqual(10)->assert(9);
  • Lowercase - v::stringType()->lowercase()->assert('xkcd');
  • Luhn - v::luhn()->assert('2222400041240011');
  • MacAddress - v::macAddress()->assert('00:11:22:33:44:55');
  • Masked - v::masked('1-@', v::email())->assert('foo@example.com');
  • Max - v::max(v::equals(30))->assert([10, 20, 30]);
  • Mimetype - v::mimetype('image/png')->assert('/path/to/image.png');
  • Min - v::min(v::equals(10))->assert([10, 20, 30]);
  • Multiple - v::intVal()->multiple(3)->assert(9);
  • Named - v::named('Your email', v::email())->assert('foo@example.com');
  • Negative - v::numericVal()->negative()->assert(-15);
  • NfeAccessKey - v::nfeAccessKey()->assert('52060433009911002506550120000007800267301615');
  • Nif - v::nif()->assert('49294492H');
  • Nip - v::nip()->assert('1645865777');
  • NoneOf - v::noneOf(v::intVal(), v::floatVal())->assert('foo');
  • Not - v::not(v::ip())->assert('foo');
  • NullOr - v::nullOr(v::email())->assert(null);
  • NullType - v::nullType()->assert(null);
  • Number - v::number()->assert(42);
  • NumericVal - v::numericVal()->assert(-12);
  • ObjectType - v::objectType()->assert(new stdClass);
  • Odd - v::odd()->assert(3);
  • OneOf - v::oneOf(v::digit(), v::alpha())->assert('AB');
  • Pesel - v::pesel()->assert('21120209256');
  • Phone - v::phone()->assert('+1 650 253 00 00');
  • Pis - v::pis()->assert('120.0340.678-8');
  • PolishIdCard - v::polishIdCard()->assert('AYW036733');
  • PortugueseNif - v::portugueseNif()->assert('124885446');
  • Positive - v::positive()->assert(1);
  • PostalCode - v::postalCode('BR')->assert('02179000');
  • Printable - v::printable()->assert('LMKA0$% _123');
  • Property - v::property('name', v::equals('The Respect Panda'))->assert($object);
  • PropertyExists - v::propertyExists('name')->assert($object);
  • PropertyOptional - v::propertyOptional('name', v::notBlank())->assert($object);
  • PublicDomainSuffix - v::publicDomainSuffix()->assert('co.uk');
  • Punct - v::punct()->assert('&,.;[]');
  • Readable - v::readable()->assert('/path/to/file.txt');
  • Regex - v::regex('/[a-z]/')->assert('a');
  • ResourceType - v::resourceType()->assert(fopen('/path/to/file.txt', 'r'));
  • Roman - v::roman()->assert('IV');
  • ScalarVal - v::scalarVal()->assert(135.0);
  • Size - v::size('KB', v::greaterThan(1))->assert('/path/to/file');
  • Slug - v::slug()->assert('my-wordpress-title');
  • Sorted - v::sorted('ASC')->assert([1, 2, 3]);
  • Space - v::space()->assert(' ');
  • Spaced - v::spaced()->assert('foo bar');
  • StartsWith - v::startsWith('lorem')->assert('lorem ipsum');
  • StringType - v::stringType()->assert('hi');
  • StringVal - v::stringVal()->assert('6');
  • SubdivisionCode - v::subdivisionCode('BR')->assert('SP');
  • Subset - v::subset([1, 2, 3])->assert([1, 2]);
  • SymbolicLink - v::symbolicLink()->assert('/path/to/symbolic-link');
  • Templated - v::templated('You must provide a valid email', v::email())->assert('foo@bar.com');
  • Time - v::time()->assert('00:00:00');
  • Tld - v::tld()->assert('com');
  • TrueVal - v::trueVal()->assert(true);
  • Undef - v::undef()->assert('');
  • UndefOr - v::undefOr(v::alpha())->assert('');
  • Unique - v::unique()->assert([]);
  • Uppercase - v::uppercase()->assert('W3C');
  • Url - v::url()->assert('http://example.com');
  • Uuid - v::uuid()->assert('eb3115e5-bd16-4939-ab12-2b95745a30f3');
  • Version - v::version()->assert('1.0.0');
  • Vowel - v::vowel()->assert('aei');
  • When - v::when(v::intVal(), v::positive(), v::notBlank())->assert(1);
  • Writable - v::writable()->assert('/path/to/file');
  • Xdigit - v::xdigit()->assert('abc123');