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

ActiveLibrary

lubaro/php-validator
====================

Validate strings, numbers and arrays according to predefined or custom defined rules.

00PHP

Since Apr 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/LubaRo/php-data-validator)[ Packagist](https://packagist.org/packages/lubaro/php-validator)[ RSS](/packages/lubaro-php-validator/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

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

[](#php-validator)

[![GitHub CI](https://github.com/LubaRo/php-oop-project-lvl1/actions/workflows/ci-check.yml/badge.svg)](https://github.com/LubaRo/php-oop-project-lvl1/actions/workflows/ci-check.yml)

Validate strings, numbers and arrays according to predefined or custom defined rules.

### Installation

[](#installation)

`composer require lubaro/php-validator`

### Validating strings

[](#validating-strings)

---

- `required()` - checks that string is exists and not empty
- `minLength(int $minLength)` - checks that the checked value length is equal or greater than passed min length value
- `contains(string $substr)` - checks that the checked value contains one or more times the passed substring

```
$v = new LubaRo\PhpValidator\Validator();

$stringValidator = $v->string(); // say to validator that we want to validate strings

$stringValidator->isValid(''); // => true
$stringValidator->required()->isValid(''); // => false

$ruleSet1 = $stringValidator->required()->contains('aka');

$ruleSet1->isValid('Checked value aka string value'); // => true
$ruleSet1->isValid('Simple string'); // => false
```

### Validating numbers

[](#validating-numbers)

---

- `required()` - checks that number is exists
- `positive()` - checks that number is greater than zero
- `range(int|float $min, int|float $max)` - checks that number value is between or equal to the provided values

```
$v = new LubaRo\PhpValidator\Validator();

$v->number()->isValid(45.15); // => true
$v->number()->isValid('45.15'); // => false
$v->number()->range(-4, 15)->isValid(0); // => true
```

### Validating arrays

[](#validating-arrays)

---

- `required()` - checks that array is exists
- `sizeof(int $size)` - checks that array size is equal to given value
- `shape(array $shape)` - checks that array contains specified elements

```
$v = new LubaRo\PhpValidator\Validator();

$v->array()->isValid([1, 2, 3]); // => true
$v->array()->sizeof(2)->isValid(['name' => 'Pablo', 'age' => 27]); // => true

$arrayShape = $v->array()->shape([
    'name' => $v->string()->required(),
    'age'  => $v->number()->positive()
]);

$arrayShape->isValid(['name' => 'Pablo', 'age' => 27, 'hobbies' => []]); // => true
$arrayShape->isValid(['name' => 'Jake', 'hobbies' => []]); // => false
$arrayShape->isValid(['name' => 'Gary', 'age' => -1800]); // => false
```

### Custom defined rules

[](#custom-defined-rules)

---

You can add own rules to any type of validators such as string, number or array

```
$v = new LubaRo\PhpValidator\Validator();

// in custom function first parameter is a validating value
// other parameters come after
// for custom functions number of parameters is not restricted
$fn = fn($checkedNumber, $param1) => $checkedNumber < $param1;

// addValidator(validatorName, customFunctionName, function);
$v->addValidator('number', 'isLessThan', $fn);

// apply custom function using test(customFuncName, ...params)
$lessThan15 = $v->number()->required()->test('isLessThan', 15);

$lessThan15->isValid(5);  // => true
$lessThan15->isValid(25); // => false
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

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://www.gravatar.com/avatar/765e1e58858b7961d99c38275978783456ab57539b42f1c68d8424652dd8cd4a?d=identicon)[lubaro](/maintainers/lubaro)

---

Top Contributors

[![LubaRo](https://avatars.githubusercontent.com/u/29543596?v=4)](https://github.com/LubaRo "LubaRo (44 commits)")

### Embed Badge

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

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

PHPackages © 2026

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