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

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

fabstract/validator
===================

Data validator library for PHP

v0.4.11(7y ago)04221[1 issues](https://github.com/Fabstract/Validator/issues)1MITPHPPHP ^7.0

Since Mar 29Pushed 5y ago2 watchersCompare

[ Source](https://github.com/Fabstract/Validator)[ Packagist](https://packagist.org/packages/fabstract/validator)[ RSS](/packages/fabstract-validator/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (1)Versions (16)Used By (1)

[![](https://avatars3.githubusercontent.com/u/36798053?s=200&v=4)](https://avatars3.githubusercontent.com/u/36798053?s=200&v=4)

 [![Build Status](https://camo.githubusercontent.com/769f56b56d971da777edd7fa2de952fa143fffa7c4af227ba7fdf4d67573ce4e/68747470733a2f2f6170692e7472617669732d63692e6f72672f4661627374726163742f56616c696461746f722e737667)](https://travis-ci.org/Fabstract/Validator) [![Total Downloads](https://camo.githubusercontent.com/bb732cff7a001ae43b6a773c2d0147640ce7523f9bf7c63fdfaa635d5683946f/68747470733a2f2f706f7365722e707567782e6f72672f6661627374726163742f76616c696461746f722f642f746f74616c2e737667)](https://packagist.org/packages/fabstract/validator) [![Latest Stable Version](https://camo.githubusercontent.com/b4af77a1ce3e7fa27efd8e0f18a2f3fa78cbb1f8a383300a33f26a90deba27c5/68747470733a2f2f706f7365722e707567782e6f72672f6661627374726163742f76616c696461746f722f762f737461626c652e737667)](https://packagist.org/packages/fabstract/validator) [![License](https://camo.githubusercontent.com/e79ad76b72cdfc43df5c168925081caddab3803ba7944006917cb8156b3dcc48/68747470733a2f2f706f7365722e707567782e6f72672f6661627374726163742f76616c696461746f722f6c6963656e73652e737667)](https://packagist.org/packages/fabstract/validator)

Validator
---------

[](#validator)

This library introduces a small framework to validate certain variables against some rules. This library is especially useful to validate client POST or form data in the backend side.

This library is fully compatible with any framework and library. You can feel free to use it with Symfony, Laravel, or whichever framework you are using with nothing to fear for.

What Does It Do?
----------------

[](#what-does-it-do)

You can use this library to check if given value is valid string, array, integer, float, whether is belongs to certain set of values, objects and so on. In case validation fails, library generates detailed messages as to why.

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

[](#installation)

**Note:** PHP 7.1 or higher is required.

1. Install [composer](https://getcomposer.org/download/).
2. Run `composer require fabstract/validator`.

How to use
----------

[](#how-to-use)

First you need to create a class that implements `ValidatableInterface` and set your validations. Let's call it `validatable`. Then you need an instance of `Validator`. Finally, set your `validatable` object's fields and validate it via `validator`. Let's check below, we will use pre-defined validation classes (for instance, StringValidation class) for this example:

```
use Fabstract\Component\Validator\ValidatableInterface;
use Fabstract\Component\Validator\Validation\PatternValidation;
use Fabstract\Component\Validator\Validation\StringValidation;
use Fabstract\Component\Validator\ValidationMetadata;
use Fabstract\Component\Validator\Validator;

// Create class
class RegistrationPostData implements ValidatableInterface
{

    // Has to be 3-30 characters
    public $name = null;
    // Has to include at least a letter and number, be between 8-32 characters
    // so, it needs to match "^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,32}$"
    public $password = null;

    /**
     * @param ValidationMetadata $validation_metadata
     * @return void
     */
    public function configureValidationMetadata($validation_metadata)
    {
        $validation_metadata
            ->addValidation('name', StringValidation::create()
                ->setMinLength(3)
                ->setMaxLength(30))
            ->addValidation('password', PatternValidation::create('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,32}$/'));
    }
}

// Create validator instance, one instance is enough
$validator = new Validator();

// Let's create instance of our RegistrationPostData and fill it with POST data
$post_data = new RegistrationPostData();
$post_data->name = $_POST['name'];
$post_data->password = $_POST['password'];

// Validate the data
$validation_error_list = $validator->validate($post_data);

// Here if validation error list is empty, it means all your post data is valid.
$is_post_data_valid = count($validation_error_list) === 0;
if (!$is_post_data_valid) {
    // If not empty, you can see meaningful validation messages like below
    foreach ($validation_error_list as $validation_error) {
        echo $validation_error;
        echo PHP_EOL;
    }
}
```

Suppose you sent a data like below:

```
curl -X POST localhost -F'name=ac' -F'password=123'

```

You will see a result like below:

```
Validation failed at "name". Message is "String must be at least 3 character(s) long.".
Validation failed at "password". Message is "Value must match pattern /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,32}$/.".

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.7% 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 ~9 days

Recently: every ~18 days

Total

15

Last Release

2832d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11666659?v=4)[Ahmet Türk](/maintainers/fabsolute)[@Fabsolute](https://github.com/Fabsolute)

![](https://www.gravatar.com/avatar/6f4080b0f9e4fa14a66343b0c230ca6fe46a1e326941ce2a98359501309b2406?d=identicon)[necipallef](/maintainers/necipallef)

---

Top Contributors

[![necipallef](https://avatars.githubusercontent.com/u/11958773?v=4)](https://github.com/necipallef "necipallef (104 commits)")[![omerkocaoglu](https://avatars.githubusercontent.com/u/29660210?v=4)](https://github.com/omerkocaoglu "omerkocaoglu (6 commits)")[![Fabsolute](https://avatars.githubusercontent.com/u/11666659?v=4)](https://github.com/Fabsolute "Fabsolute (1 commits)")

---

Tags

phpvalidator

### Embed Badge

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

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

###  Alternatives

[runz0rd/mapper-php

Model mapping, unmapping and validation

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

PHPackages © 2026

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