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.1k↑11.8%[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 1mo ago

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 27% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity29

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

1950d 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

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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