PHPackages                             dhii/validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. dhii/validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

dhii/validator
==============

A thin, standards-compliant validator implementation.

v0.1.0-alpha1(5y ago)140.5k↓42.2%[1 issues](https://github.com/Dhii/validator/issues)MITPHPPHP ^7.1 | ^8.0

Since Jan 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Dhii/validator)[ Packagist](https://packagist.org/packages/dhii/validator)[ RSS](/packages/dhii-validator/feed)WikiDiscussions develop Synced yesterday

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Dhii - Validator
================

[](#dhii---validator)

A thin, standards-compliant validator implementation of [`dhii/validation-interface`](https://github.com/Dhii/validation-interface).

Details
-------

[](#details)

This is a super-lightweight validation library that allows easy creation of validation structures of arbitrary depth.

### Examples

[](#examples)

A validator ensures values are valid usernames. It is a composite validator, comprised of 2 simple validators:

1. Ensures values are alphanumeric strings.
2. Ensures value lengths are less than or equal to 30 characters.

This validator hierarchy throws a hierarchy of exceptions when failing:

1. Composite validator's failure exception reports how many failures occurred, and exposes failure exceptions from the simple validators.
2. Those in turn report what exactly was invalid.

```
use Dhii\Validation\Exception\ValidationFailedExceptionInterface;use Dhii\Validator\CallbackValidator;
use Dhii\Validator\CompositeValidator;

$alphanum = new CallbackValidator(function ($value) {
    if (preg_match('![^\d\w]!', $value, $matches)) {
        return sprintf('Value "%1$s" must be alphanumeric, but contains char "%2$s"', $value, $matches[0][0]);
    }
});
$chars30 = new CallbackValidator(function ($value) {
    $length = strlen($value);
    if (!($length validate('abcdef');

// Invalid username value: exception thrown
try {
    $percentValidator->validate('abcdefghijklmnopqrstuvwxyz!@#$%');
} catch (ValidationFailedExceptionInterface $e) {
    // Validation failed with 2 errors.
    echo $e->getMessage();
    // 1: Value "abcdefghijklmnopqrstuvwxyz!@#$%" must be alphanumeric, but contains char "!"
    // 2: Value "abcdefghijklmnopqrstuvwxyz!@#$%" is limited to 30 characters, but is 31 characters long
    foreach ($e->getValidationErrors() as $error) {
        echo (string) $error;
    }
}
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1995d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1894e91b32c9f80d8f30a42d360af6983a507f1cf2c621b7c9a0a0de14e011c5?d=identicon)[XedinUnknown](/maintainers/XedinUnknown)

---

Top Contributors

[![XedinUnknown](https://avatars.githubusercontent.com/u/1428973?v=4)](https://github.com/XedinUnknown "XedinUnknown (31 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dhii-validator/health.svg)

```
[![Health](https://phpackages.com/badges/dhii-validator/health.svg)](https://phpackages.com/packages/dhii-validator)
```

###  Alternatives

[marcosh/php-validation-dsl

A DSL for validating data in a functional fashion

483.9k](/packages/marcosh-php-validation-dsl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
