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

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

solbianca/validator
===================

Easy to use, highly customisable PHP validator.

v1.0(8y ago)010MITPHPPHP &gt;=7.1

Since Dec 23Pushed 8y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

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

[](#php-validator)

This is an easy to use and customisable PHP validator.

**Note: This package is under development and not recommended for production.**

[![Build Status](https://camo.githubusercontent.com/fbdbb39593fe18178902ac20f5bde58d963e4c44d1e069a29595e08d3eca8fa0/68747470733a2f2f7472617669732d63692e6f72672f736f6c6269616e63612f76616c696461746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/solbianca/validator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/985099651a515606425bc2bf8e8de4b9a2c0f038131e979707ebd84aa3cefed6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6c6269616e63612f76616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/solbianca/validator/?branch=master)[![Maintainability](https://camo.githubusercontent.com/20bcdae1a954ca4aa7a451a4991dd8b3bf92104b13c0458bc5b29eac0b018fc6/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f37633231316338383435613633323239653863642f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/solbianca/validator/maintainability)

Installing
----------

[](#installing)

Install via composer

```
composer require solbianca/validator
```

or add to composer.json

```
{
    "require": {
        "solbianca/php-validator": "1.*"
    }
}
```

Basic usage
-----------

[](#basic-usage)

```
use SolBianca\Validator;

$validator = new Validator;

$validator->validate([
    'age' => ['value' => 20, 'rules' => ['required', 'int']],
    'name' => ['value' => 'John Doe', 'rules' => ['required']],
]);

if($validator->passed()) {
    echo 'Validation passed!';
} else {
    var_dump($validator->errors()->all();
}
```

Adding custom rules
-------------------

[](#adding-custom-rules)

Adding custom rules is simple. It can be any callable or object which implement `SolBianca\Validator\Interfaces\RuleInterface`

If the callable returns false, the rule fails.

```
$validator->addRule('sex', function ($value) {
    return in_array($value, ['male', 'female']);
})->addRuleMessage('sex', 'Field `{field}` must be male or female. Given value `{value}`.');

$validator->validate([
    'fruit' => ['value' => 'male', 'rules' => ['sex']],
]);
```

```
class SomeRule implements SolBianca\Validator\Interfaces\RuleInterface
{
    // some code
}

// You can add as a string
$validator->addRule('sex', SomeRule::class);

// or as an object
$validator->addRule('sex', new SomeRule());
```

Rewrite rules
-------------

[](#rewrite-rules)

Validator have useful default rules as `int`, `required` and many more. You can rewrite any rule by your own.

```
$validator->addRule('int', function ($value) {
    return (is_int($value)) && $value > 0);
})->addRuleMessage('sex', 'Field `{field}` must be integer ang greater than zero.');

$validator->validate([
    'fruit' => ['value' => 'male', 'rules' => ['sex']],
]);
```

Adding custom error messages
----------------------------

[](#adding-custom-error-messages)

You can add custom error messages for any rule

```
$validator->addRuleMessage('required', 'You better fill in the {field} field, or else.');
```

Adding rule messages in bulk
----------------------------

[](#adding-rule-messages-in-bulk)

```
$v->addRuleMessages([
    'required' => 'You better fill in the {field} field, or else.',
    'int'      => 'The {field} needs to be an integer, but I found {value}.',
]);
```

Using Field Aliases
-------------------

[](#using-field-aliases)

Field Aliases helps you format any error messages without showing weird form names or the need to create a custom error.

```
$validator->validate([
    'username_box' => ['value' => '', 'rules' => ['required'], 'alias' => 'Username']
]);

// Error output: "Field `Username` is required."
```

Rules
-----

[](#rules)

#### Array

[](#array)

If the value is an array.

```
$validator->validate([
    'some_input' => ['value' => [10, 20], 'rules' => ['array']],
]);
```

#### Between

[](#between)

Checks if the value is within the intervals defined. This check is inclusive, so 5 is between 5 and 10.

```
$validator->validate([
    'some_input' => ['value' => 5, 'rules' => ['between' => [5, 10]]],
]);
```

#### Bool

[](#bool)

If the value is a boolean.

```
$validator->validate([
    'some_input' => ['value' => true, 'rules' => ['bool']],
]);
```

#### Email

[](#email)

If the value is a valid email.

```
$validator->validate([
    'some_input' => ['value' => 'mail@example.com', 'rules' => ['email']],
]);
```

#### Int

[](#int)

If the value is an integer, including numbers within strings. 1 and '1' are both classed as integers.

```
$validator->validate([
    'some_input' => ['value' => 42, 'rules' => ['int']],
]);
```

#### Ip

[](#ip)

If the value is a valid IP address.

```
$validator->validate([
    'some_input' => ['value' => '127.0.0.1', 'rules' => ['ip']],
]);
```

#### Matches

[](#matches)

Checks if one given input matches the other. For example, checking if password matches password\_confirm.

```
$validator->validate([
    'some_input' => ['value' => 1, 'rules' => ['int', 'matches' => 'other_input']],
    'other_input' => ['value' => 1, 'rules' => ['int']]
]);
```

#### Max

[](#max)

Check if string length is less than or equal to given int. To check the size of a number, pass the optional number option.

```
$validator->validate([
    'some_input' => ['value' => 5, 'rules' => ['max' => 10]],
    'other_input' => ['value' => 0.5, 'rules' => ['max' => [1.0, 'number']]],
]);
```

#### Mix

[](#mix)

Check if string length is greater than or equal to given int. To check the size of a number, pass the optional number option.

```
$validator->validate([
    'some_input' => ['value' => 5, 'rules' => ['min' => 1]],
    'other_input' => ['value' => 0.5, 'rules' => ['min' => [0.0, 'number']]],
]);
```

#### Number

[](#number)

If the value is a number, including numbers within strings.

> Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal (e.g. 0xf4c3b00c), Binary (e.g. 0b10100111001), Octal (e.g. 0777) notation is allowed too but only without sign, decimal and exponential part.

```
$validator->validate([
    'some_input' => ['value' => '5', 'rules' => ['number']],
]);
```

#### Regex

[](#regex)

If the given input has a match for the regular expression given.

```
$validator->validate([
    'some_input' => ['value' => 'bag', 'rules' => ['regex' => '/b[aeiou]g/']],
]);
```

#### Required

[](#required)

If the value is present.

```
$validator->validate([
    'some_input' => ['value' => true, 'rules' => ['required']],
]);
```

#### Url

[](#url)

If the value is formatted as a valid URL.

```
$validator->validate([
    'some_input' => ['value' => 'http://example.com', 'rules' => ['url']],
]);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

3065d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f7a490f4573a3a3994e8d8def59ec31ca7201be4e7729b56d9273c93cfddfa2?d=identicon)[solbianca](/maintainers/solbianca)

---

Top Contributors

[![solbianca](https://avatars.githubusercontent.com/u/5719760?v=4)](https://github.com/solbianca "solbianca (22 commits)")

---

Tags

validatorvalidation

###  Code Quality

TestsCodeception

### Embed Badge

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

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[vlucas/valitron

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

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

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M30](/packages/wixel-gump)

PHPackages © 2026

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