-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Muhammet Şafak edited this page Jun 10, 2026
·
2 revisions
Welcome to the official documentation for initphp/validation — a fast,
dependency-free data-validation library for PHP 8.1+.
You describe what each field should look like with a small rule DSL, callbacks, or your own named rules, and get back localized error messages.
composer require initphp/validationuse InitPHP\Validation\Validation;
$validation = new Validation([
'name' => 'Muhammet',
'year' => '2022',
]);
$valid = $validation
->rule('name', 'required|string')
->rule('year', 'integer|range(1970...2099)')
->validation();
if (!$valid) {
foreach ($validation->getError() as $message) {
echo $message, "\n";
}
}| Symbol | Role |
|---|---|
Validation |
The single entry point: holds the data, the rule queue, the errors and the active locale. |
extend() |
Register a reusable named rule usable from the DSL string. |
ExceptionInterface |
Marker implemented by every exception the package throws. |
UndefinedRuleException |
Thrown when a rule name is unknown — unknown rules fail loudly, they never silently pass. |
- New to the package? Read Installation, then Quick Start.
- Want the mental model? The Validation Lifecycle explains the queue → validate → read loop.
- Looking for a rule? Every built-in rule is in the Rules Reference.
- Need custom logic? Callable & Custom Rules.
- Localizing messages? Error Messages and Localization.
- Coming from 1.x? Read Migration from 1.x — 2.0 is a breaking release.
-
A readable rule DSL. Pipe rules together per field:
"required|integer|range(1...10)". Arguments go in parentheses and are trimmed. See the Rules Reference. - 30+ built-in rules for types, text, contact info, sizes, dates, patterns and comparisons.
-
Callbacks and custom named rules. Drop in a closure for a one-off check,
or register a reusable rule with
extend(). - Localized messages. Ships with English and Turkish; placeholders, labels and per-rule overrides are all supported. See Localization.
- Fails loud, not silent. An unknown rule throws instead of quietly passing a field. See Exceptions.
-
Zero runtime dependencies beyond
ext-mbstring.
| Rule | Passes | Fails |
|---|---|---|
integer |
"12", -3
|
"3.5", "abc"
|
mail |
a@b.com |
not-an-email |
range(1970...2099) |
2022 |
1900 |
length(3...20) |
"hello" |
"ab" |
again(password) |
confirm equals password
|
they differ |
only(small, medium, large) |
"Medium" |
"xl" |
- License: MIT
- Minimum PHP: 8.1
-
Required extensions:
ext-mbstring - Runtime dependencies: none
-
Packagist:
initphp/validation - Source: github.com/InitPHP/Validation
- Issues: github.com/InitPHP/Validation/issues
- Discussions: github.com/orgs/InitPHP/discussions
If something in this wiki is unclear, wrong, or out of date, open an issue — documentation fixes are merged eagerly.
initphp/validation · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Rules
Extending
Messages
Reference
Guides
Other