Lightweight PHP validation library: rule strings compiled once, strict about configuration, one structured error per field.
- Built-in Rules — required, required_if / with / without, prohibited_if, present, email, phone, uuid, date, min / max in characters or bytes, 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
composer require solophp/validatorThe phone rule also needs libphonenumber:
composer require giggsey/libphonenumber-for-php-liteuse 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!";
}Upgrading from 3.x? See UPGRADE.md.
- PHP 8.3+
MIT License. See LICENSE for details.