PHPackages                             district5/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. district5/validator

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

district5/validator
===================

District5 Validator Library

2.1.0(1y ago)02092mitPHPPHP &gt;=7.4

Since May 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/district-5/php-validator)[ Packagist](https://packagist.org/packages/district5/validator)[ Docs](https://github.com/district-5/php-validator)[ RSS](/packages/district5-validator/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (8)Used By (2)

[![codecov](https://camo.githubusercontent.com/78542078786d0f966a525939f01ae3aea8b5eddb0785c20533338f2ea18aae8e/68747470733a2f2f636f6465636f762e696f2f67682f64697374726963742d352f7068702d76616c696461746f722f67726170682f62616467652e7376673f746f6b656e3d51325738423455433843)](https://codecov.io/gh/district-5/php-validator)

District5 Validator Library
===========================

[](#district5-validator-library)

About
-----

[](#about)

This library provides the skeletons to support validators.

Installing
----------

[](#installing)

This library requires no other libraries.

```
composer require district5/validator

```

Usage
-----

[](#usage)

### Validator

[](#validator)

To create an implementation of a validator you will need to implement the `\District5\Validator\ValidatorInterface` interface or extend the provided Abstract Class `\District5\Validator\AbstractValidator`.

An example validator for a StringLength validator might look as follows:

```
use \District5\Validator\AbstractValidator;

class StringLengthValidator extends AbstractValidator
{
    protected $errorMessages = [
        'notString' => 'Value is not a string',
        'tooShort' => 'Value is below the minimum string length',
        'tooLong' => 'Value exceeds the maximum string length'
    ];

    private $min;

    private $max;

    public function __construct(int $min, int $max)
    {
        parent::__construct();

        $this->min = $min;
        $this->max = $max;
    }

    public function isValid($value): bool
    {
        if (!is_string($value)) {
            $this->setLastErrorMessage('notString');
            return false;
        }

        $len = strlen($value);

        if ($len > $this->max) {
            $this->setLastErrorMessage('tooLong');
            return false;
        }

        if ($len < $this->min) {
            $this->setLastErrorMessage('tooShort');
            return false;
        }

        return true;
    }
}
```

Issues
------

[](#issues)

Log a bug report!

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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

Every ~382 days

Recently: every ~573 days

Total

7

Last Release

668d ago

Major Versions

1.0.3 → 2.0.02024-02-25

PHP version history (3 changes)1.0.0PHP &gt;=5.4.0

2.0.0PHP &gt;=7.1

2.1.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/5de4b9a90eadf6b595e1b5efc802683f2358da5661c616820b90c922f8aa8e05?d=identicon)[rogerthomas84](/maintainers/rogerthomas84)

![](https://avatars.githubusercontent.com/u/1934581?v=4)[Mark Morgan](/maintainers/mark-morgan)[@mark-morgan](https://github.com/mark-morgan)

---

Top Contributors

[![mark-morgan](https://avatars.githubusercontent.com/u/1934581?v=4)](https://github.com/mark-morgan "mark-morgan (23 commits)")

---

Tags

phpvalidatordistrict5

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[runz0rd/mapper-php

Model mapping, unmapping and validation

17474.4k2](/packages/runz0rd-mapper-php)

PHPackages © 2026

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