solophp/validator

PHP Data Validator

Installs: 141

Dependents: 1

Suggesters: 1

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/solophp/validator

v3.0.0 2026-02-17 13:20 UTC

This package is auto-updated.

Last update: 2026-02-17 13:20:59 UTC


README

Lightweight PHP validation library with custom rules and structured errors.

Latest Version on Packagist PHP Version License

Features

  • Built-in Rules — Required, email, phone, uuid, min, max, length, numeric, date, and more
  • Custom Rules — Extend validation with your own rules via callbacks
  • Structured Errors — Machine-readable error objects with rule names and parameters
  • Parameterized Rules — Define rules like min:8, max:100, in:a,b,c
  • Phone Validation — International phone validation via libphonenumber
  • Lightweight — Minimal dependencies, PSR-4 compliant

Installation

composer require solophp/validator

Quick Example

use Solo\Validator\Validator;

$validator = new Validator();

$data = [
    'email' => 'user@example.com',
    'username' => 'john_doe',
    'age' => 25,
];

$rules = [
    'email' => 'required|email',
    'username' => 'required|min:3|max:20',
    'age' => 'integer|min_value:18',
];

$errors = $validator->validate($data, $rules);

if ($validator->fails()) {
    print_r($validator->errors());
    // [
    //     'field' => [
    //         ['rule' => 'email'],
    //         ['rule' => 'min', 'params' => ['3']],
    //     ],
    // ]
} else {
    echo "Validation passed!";
}

Documentation

Full Documentation

Requirements

  • PHP 8.1+

License

MIT License. See LICENSE for details.