PHPackages                             laurynasgadl/php-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. laurynasgadl/php-validator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laurynasgadl/php-validator
==========================

Array value validation library for PHP

v3.0.0(2y ago)2452.2k↓71.5%3MITPHPPHP &gt;=8.0CI failing

Since Oct 21Pushed 2y ago1 watchersCompare

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

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

PHP-Validator
=============

[](#php-validator)

*inspired by Laravel's form validation*

```
use Luur\Validator\Validator;
use Luur\Validator\Rules\Concrete\MinRule;
use Luur\Validator\Rules\Concrete\RequiredRule;
use Luur\Validator\Exceptions\ValidationFailed;

$validator = new Validator();

$rules = [
    'client_id'    => 'required|integer',
    'amount'       => [new RequiredRule(), new MinRule(0)],
    'count'        => 'between:-12,50',
    'details'      => 'array|required',
    '*.name'       => 'string|required',
];

$params = [
    'client_id' => 12345,
    'amount'    => 1234,
    'details'   => [
        'name'  => 'John Doe',
    ],
];

try {
    $allParams       = $validator->validate($rules, $params);
    $validatedParams = $validator->validated();
} catch (ValidationFailed $exception) {
    var_dump($exception->getMessage());
}
```

Installation
============

[](#installation)

`composer require laurynasgadl/php-validator`

Documentation
=============

[](#documentation)

Rules
-----

[](#rules)

#### Custom rules

[](#custom-rules)

```
use Luur\Validator\Rules\AbstractRule;
use Luur\Validator\Validator;

class CustomRule extends AbstractRule {
    /**
     * @param mixed $value
     * @return bool
     */
    public function passes($value)
    {
        return true;
    }
}

$validator = new Validator();

$params = ['test' => 123];
$result = $validator->validate([
    'test' => new CustomRule(),
], $params);
```

You can also register the rule to be able to use it as a string:

```
use Luur\Validator\Rules\AbstractRule;
use Luur\Validator\Validator;

class CustomRule extends AbstractRule {
    /**
     * @param mixed $value
     * @return bool
     */
    public function passes($value)
    {
        return true;
    }
}

$validator = new Validator();
$validator->registerRule(CustomRule::getSlug(), CustomRule::class);

$params = ['test' => 123];
$result = $validator->validate([
    'test' => 'test',
], $params);
```

#### Existing rules

[](#existing-rules)

`array` : the value needs to be an array

`between:{from_size},{to_size}` : the value needs to be between the given range

`float` : the value needs to be a float

`integer` : the value needs to be an integer

`max:{max_size}` : the value needs to be less or equal to the given amount

`min:{min_size}` : the value needs to be greater or equal to the given amount

`required` : the parameter needs to exist in the data set

`required_with:{param_1}...` : the parameter needs to exist in the data set if all the other parameters exist

`required_without:{param_1}...` : the parameter needs to exist in the data set if one of the other parameters do not exist

`size` : the size of the value needs to be equal to the given amount. The size of a string is its length, the size of an array is the number of elements inside it, the size of a boolean is 0 or 1.

`string` : the value needs to be a string

`boolean` : the value needs to be a boolean

`numeric` : the value needs to be a numeric

`default:{value}` : the rule will always be applied first, meaning, params can successfully pass `required` rules even if their value is not set or is null

`alpha_dash` : the value can only be made up of uppercase and lowercase letters, numbers and `-` or `_` symbols

`alpha_numeric` : the value can only be made up of uppercase and lowercase letters and numbers

`regex:{pattern}` : the value needs to match the given pattern

`email` : the value needs to be an email

`url` : the value needs to start with `http://` or `https://` and only contain URL-valid symbols

`ip` : the value needs to be an IP address

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

[](#custom-messages)

You can set custom validation messages either via the Validator constructor or the `validate` method:

```
use Luur\Validator\Validator;

$validator = new Validator();

$rules = [
    'options.*.key' => 'string|required',
];

$params = [
    'options' => [
        [
            'key' => 'passes',
            'value' => true,
        ],
        [
            'key' => ['passes'],
            'value' => false,
        ],
    ],
];

$messages = [
    'options.*.key.string' => 'Option key should be a string',
];

$validator->validate($rules, $params, $messages);
```

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 93.9% 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 ~62 days

Recently: every ~286 days

Total

23

Last Release

1081d ago

Major Versions

1.1.7 → 2.0.02020-05-08

2.3.0 → v3.0.02023-07-19

PHP version history (3 changes)v1.0.0PHP &gt;=5.6

2.3.0PHP &gt;=7.0

v3.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/96be8579ec0431ecc7a87ea091e9eaf1a45d8c662c6b12d1338bd05b21cb964f?d=identicon)[laurynasgadl](/maintainers/laurynasgadl)

---

Top Contributors

[![laurynasgadl](https://avatars.githubusercontent.com/u/30233941?v=4)](https://github.com/laurynasgadl "laurynasgadl (31 commits)")[![MantasPetrauskas93](https://avatars.githubusercontent.com/u/61971764?v=4)](https://github.com/MantasPetrauskas93 "MantasPetrauskas93 (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

packagephpphp-validatorvalidationphpvalidatorvalidationarray

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[lezhnev74/pasvl

Array Validator (regular expressions for nested array, sort of)

5258.3k3](/packages/lezhnev74-pasvl)

PHPackages © 2026

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