PHPackages                             pbrus/validation-engine - 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. pbrus/validation-engine

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

pbrus/validation-engine
=======================

011PHP

Since May 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/pbrus/validation-engine)[ Packagist](https://packagist.org/packages/pbrus/validation-engine)[ RSS](/packages/pbrus-validation-engine/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Validation-engine
=================

[](#validation-engine)

[![Written in PHP](https://camo.githubusercontent.com/b825ebf92a08b110c62da1bffa3be1057ee3fd1ace3918ef201e3ba67633b10d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652d5048502d626c75652e737667 "language")](https://www.php.net/)[![License](https://camo.githubusercontent.com/07a7d0169027aac6d7a0bfa8964dfef5fbc40d5a2075cabb3d8bc67e17be3451/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d79656c6c6f772e737667 "MIT license")](https://github.com/pbrus/validation-engine/blob/master/LICENSE)

This is a simple validation engine written in PHP OOP for fun. If you need a robust PHP validator I recommend [this one](https://github.com/Respect/Validation).

Installation
------------

[](#installation)

Install the package using *Composer*:

```
$ composer require pbrus/validation-engine=dev-master
```

Then go to the `validation-engine/` directory and make `dump-autoload`:

```
$ cd vendor/pbrus/validation-engine/
$ composer dump-autoload
```

If don't know what *Composer* is, see the [simplified PHP installation](https://github.com/pbrus/astro-quiz#installation).

Usage
-----

[](#usage)

Define a validator and set its labels (here `username` and `id`):

```
$validator = new ValidationEngine();

$validator->setLabels(array(
    'username',
    'id'
));
```

In the next step set constraints for each label:

```
$validator->setConstraints('username', array(
    new NotEmptyValidator(array(
        'notEmptyMessage' => 'Field username must be filled out'
    )),
    new LengthValidator(array(
        'minLength' => 3,
        'maxLength' => 25,
        'lengthMessage' => "Field username must contain 3-25 letters"
    ))
));

$validator->setConstraints('id', array(
    new NotEmptyValidator(array(
        'notEmptyMessage' => "You must type your ID"
    )),
    new LengthValidator(array(
        'minLength' => 10,
        'maxLength' => 10,
        'lengthMessage' => "Field ID must consist of 10 integers"
    ))
));
```

Then we can validate data:

```
if (!$validator->setFields(array(
    'username' => 'John',   // not validated: 'Jo'
    'id' => '9876543210'    // not validated: '123'
))
) {
    echo $validator->getErrorMessage();
}
```

If you encounter any problems, please see the demo file `index.php`.

Classes
-------

[](#classes)

The following examples of classes are defined:

- NotEmptyValidator
- LengthValidator

Feel free to add own classes.

License
-------

[](#license)

**Validation-engine** is licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19304263?v=4)[Przemysław Bruś](/maintainers/PBrus)[@pbrus](https://github.com/pbrus)

---

Top Contributors

[![pbrus](https://avatars.githubusercontent.com/u/19304263?v=4)](https://github.com/pbrus "pbrus (10 commits)")

### Embed Badge

![Health badge](/badges/pbrus-validation-engine/health.svg)

```
[![Health](https://phpackages.com/badges/pbrus-validation-engine/health.svg)](https://phpackages.com/packages/pbrus-validation-engine)
```

PHPackages © 2026

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