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

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

redot/validator
===============

Validation framework lets you configure, rather than code, your validation logic.

0.0.1(3y ago)34MITPHPPHP &gt;=8.0

Since Sep 24Pushed 2y agoCompare

[ Source](https://github.com/redot-src/php-validator)[ Packagist](https://packagist.org/packages/redot/validator)[ RSS](/packages/redot-validator/feed)WikiDiscussions master Synced 1mo ago

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

PHP Validator
=============

[](#php-validator)

[![tests](https://github.com/redot-src/php-validator/actions/workflows/php.yml/badge.svg)](https://github.com/redot-src/php-validator/actions/workflows/php.yml)

*Validation library lets you configure, rather than code, your validation logic.*

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

[](#installation)

```
composer require redot/validator
```

Testing
-------

[](#testing)

```
composer test
```

Usage
-----

[](#usage)

After registering the rules that you want to use, you can use the validator like this:

```
use Redot\Validator\Validator;

/* Instantiate a new validator */
$validator = new Validator($email);

/* Or you can use the static method init */
$validator = Validator::init($email);

/* Apply your rules */
$validator->email()->required()->max(255);

if (!$validator->validate()) {
    return $validator; // validation result in JSON format
}
```

Also, you can validate multiple values at once:

```
$errors = Validator::initMultiple($_POST, [
    'email' => 'email',
    'password' => 'required|min:6|max:255'
]);

if (count($errors)) {
    // do something
}
```

*Note that multiple validations return an array of failures rather than a Validator instance.*

Btw, you can validate values statically:

```
$isEmail = Validator::email('admin@example.com'); // true
```

Registering rules
-----------------

[](#registering-rules)

The validator came without any registered rules by default. You can add them by using the `Validator::addRule()` method.

```
use Redot\Validator\Rules\RequiredRule;

Validator::addRule(RequiredRule::class);
```

Also you can load the default rules by using the `Validator::loadDefaultRules()` method.

```
Validator::loadDefaultRules();
```

Loading the default rules will register the following rules:

RuleDescriptionParameters`alpha`The value must contain only alphabetic characters.-`between`The value must be between the given min and max.min: `int`, max: `int``contains`The value must contain all the given values.`mixed[]``doesntContain`The value must not contain all the given values.`mixed[]``each`The value must be an array and each item must pass the given rule.`callable``email`The value must be a valid email address.-`equal`The value must be equal to the given value.`mixed``date`The value must be a valid date.-`max`The value must be less than or equal to the given value.`int``min`The value must be greater than or equal to the given value.`int``pattern`The value must match the given pattern.`string``required`The value must be present.-`string`The value must be a string.-`number`The value must be a number.-`array`The value must be an array.-*You can submit a pull request to add a new rule.*

Custom rules
------------

[](#custom-rules)

If you have a specific rule you want to use, you can create a class that extends `Validator\AbstractRule` and register it.

```
class CustomRule extends AbstractRule
{
    protected string $message = '...';

    public function getName(): string
    {
        // name will be used to call the rule
    }

    public function validate(mixed $value, mixed ...$params): bool
    {
        // validation logic
    }
}
```

Custom messages
---------------

[](#custom-messages)

If you want to customize the error messages, you can use the `Validator::setMessages()` method.

```
Validator::setMessages([
    'required' => 'The value is required.',
    'email' => 'The value is not a valid email.',
    'max' => 'The value should be less than or equal to {0}.',
]);
```

*Note that you can pass parameters to the message using `{x}` placeholders where `x` is the index of the parameter.*

That's it. Enjoy 👌!

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

1329d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2fe62c6597d6411df01b9d1c769a0134d825b1462dc7bad4c2524d4150019a5a?d=identicon)[AbdelrhmanSaid](/maintainers/AbdelrhmanSaid)

---

Top Contributors

[![AbdelrhmanSaid](https://avatars.githubusercontent.com/u/70618755?v=4)](https://github.com/AbdelrhmanSaid "AbdelrhmanSaid (100 commits)")

---

Tags

validatorphpvalidatorvalidationredot

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[vlucas/valitron

Simple, elegant, stand-alone validation library with NO dependencies

1.6k4.4M128](/packages/vlucas-valitron)

PHPackages © 2026

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