Search by

solophp / validator

Vitaliy Olos

PHP Data Validator

Package info

github.com/SoloPHP/Validator

pkg:composer/solophp/validator

Statistics

Installs: 258

Dependents: 4

Suggesters: 2

Stars: 1

Open Issues: 0

v4.2.0 2026-10-28 14:06 UTC

README

Lightweight PHP validation library: rule strings compiled once, strict about configuration, one structured error per field.

Latest Version on Packagist PHP Version License

Features

  • Built-in Rules — required, required_if / with / without, prohibited_if, present, email, phone, uuid, date, min, max, in, regex and more
  • Fails Fast — an unknown rule or a bad parameter throws on first use instead of silently validating nothing
  • Structured Errors — at most one machine-readable error per field: the rule name and its parameters
  • Custom Rules — callables or classes, registered in the constructor
  • Stateless — validate() returns the errors, so one instance can be shared across requests and workers
  • Request-Handler ready — the validator behind solophp/request-handler 4: the same rule grammar, the same reading of types

Installation

composer require solophp/validator

The phone rule also needs libphonenumber:

composer require giggsey/libphonenumber-for-php-lite

Quick Example

use Solo\Validator\Validator;

$validator = new Validator();

$errors = $validator->validate(
    ['email' => 'user@example', 'username' => 'jo', 'age' => '25'],
    [
        'email' => 'required|email',
        'username' => 'required|min:3|max:20',
        'age' => 'integer|min_value:18',
    ],
);

// [
//     'email' => [['rule' => 'email']],
//     'username' => [['rule' => 'min', 'params' => ['3']]],
// ]

if ($errors === []) {
    echo "Validation passed!";
}

Documentation

Full Documentation

Upgrading from 3.x? See UPGRADE.md.

Requirements

  • PHP 8.3+

License

MIT License. See LICENSE for details.