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

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

crtl/validation
===============

1.0.0(7y ago)05Apache-2.0PHPPHP &gt;=7.2

Since Sep 9Pushed 7y agoCompare

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

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

Validation Framework
====================

[](#validation-framework)

Feature Requirements
--------------------

[](#feature-requirements)

1. Easy to use
2. Easy to extend
3. Basic functionality

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

[](#installation)

```
composer require crtl/validation

```

Usage
-----

[](#usage)

```
use Crtl\Validation\Custom\Rule as CustomRule;

require_once(__DIR__ . "/vendor/autoload.php");

$validator = new Crtl\Validation\Validator([
    "ruleName" => ["fieldName1", ..., "fieldNameN"],
    "ruleName" => ["fieldName" => "configValue"],
    "ruleName" => ["fieldName" => ["config1", "config"]],
    CustomRule::class => ["fieldName", ...]
]);

if (!$validator->validate($data)) {
    $errors = $validator->getErrors();
}
```

Built In Rules
--------------

[](#built-in-rules)

- required
- boolean
- number
- float
- int
- min `[value, exclusive:bool=false]`
- max `[value, exclusive:bool=false]`
- string
- length
- minLength `[value, exclusive:bool=false]`
- maxLength `[value, exclusive:bool=false]`
- array
- count
- maxCount `[value, exclusive:bool=false]`
- minCount `[value, exclusive:bool=false]`
- email
- ip
- ipv6
- ipv4
- alnum
- digit
- mac
- domain
- url
- pattern
- equals `[value, strict:bool=false]`

Define Custom Validation Rules
------------------------------

[](#define-custom-validation-rules)

To define custom validation rules you can either implement the `Crtl\Validation\RuleInterface` or the `Crtl\Validation\SingleInstanceRuleInterface`.

The `Crtl\Validation\SingleInstanceRuleInterface` will be only instantiated once.

```
class UniqueDbColumnRule implements \Crtl\Validation\RuleInterface {

    protected $connection;
    protected $table;
    protected $column;

    public function __construct(array $config) {
        $this->connection = $config[0] ?? null;
        $this->table = $config[0] ?? null;
        $this->column = $config[0] ?? null;
    }

    public function getName() {
        return self::class;
    }

    public function validate($value): bool {
        $stmt = $this->db->prepare(
            sprintf("SELECT %$2s FROM %$s WHERE %$2s=? LIMIT 1;", $this->table, $this->column)
        );

        $stmt->bindValue(1, $value);
        $stmt->execute();
        return $stmt->rowCount() === 0;
    }

}

$validator = new Crtl\Validation\Validator([
    UniqueDbColumnRule::class => [
        "username" => [$db, "users", "username"],
        "email" => [$db, "users", "email"]
    ]
]);

$validator->validate($data);
```

Errors
------

[](#errors)

Errors can be retrieved by calling `Crtl\Validation\Validator::getErrors`. Errors are resetted by calling `Crtl\Validation\Validator::validate`.

`Crtl\Validation\Validator::getErrors` returns an array with the following format:

```
[
   "fieldName" => ["validatorName1", "validatorName2", ...],
   ...
]

```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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

2805d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e5628d83cd6431df9b6f835e6ac7ce9438ddf1fc6871af1b17d53b4d7f80826c?d=identicon)[crtl](/maintainers/crtl)

---

Top Contributors

[![crtl](https://avatars.githubusercontent.com/u/25827827?v=4)](https://github.com/crtl "crtl (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)
