PHPackages                             boomerang/validatr - 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. boomerang/validatr

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

boomerang/validatr
==================

Simple, multilingual, standalone PHP Validator class - Validatr.

v0.1.5(12y ago)831MITPHPPHP &gt;=5.3.0

Since Jan 19Pushed 10y ago1 watchersCompare

[ Source](https://github.com/booomerang/Validatr)[ Packagist](https://packagist.org/packages/boomerang/validatr)[ Docs](https://github.com/booomerang)[ RSS](/packages/boomerang-validatr/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (11)Used By (0)

\#Validatr

[![Build Status](https://camo.githubusercontent.com/3d6e0286cfdabd6fc98f755282c7d50db307c9ef4e7dd6b2ac8b09a852623193/68747470733a2f2f7472617669732d63692e6f72672f626f6f6f6d6572616e672f56616c69646174722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/booomerang/Validatr)

Validatr is a simple multilingual PHP Validation library for checking user's data.

- Simple form for rules and errors messages
- Flexible and extendable library with your callback rules
- Enjoyment!

Validatr is a standalone PHP class, which can be extended for your needs.

Table of contents
-----------------

[](#table-of-contents)

- [Getting started](#getting-started)
- [Installation](#installation)
- [How to use](#how-to-use)
- [Contributing](#contributing)
- [Versioning](#versioning)
- [Authors](#authors)
- [Copyright and license](#copyright-and-license)

Getting started
---------------

[](#getting-started)

1. PHP &gt;= 5.4 is required
2. Install Validatr convenient for you
3. Check your data with Validatrs rules
4. Enjoy!

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

[](#installation)

1. Via composer

```
{
    "require": {
        "boomerang/validatr": "~3.0"
    }
}

```

To download the library run the command:

```
$ php composer.phar require boomerang/validatr

```

or

```
$ composer require boomerang/validatr

```

2. Git clone

```
git clone git@github.com:booomerang/Validatr.git

```

3. Download

[Download .zip](https://github.com/booomerang/Validatr/archive/master.zip "Download .zip")

Unzip it and copy the directory into your PHP project directory.

How to use
----------

[](#how-to-use)

Simple Form

```

    Checkbox

```

Form Handler with Validatr class

```
// Set rules for some fields in form
$rules = [
    'name' => 'required|min:3|max:15|equal:Awesome:[s]',
    'password' => 'required|min:3|custom_equal:OK', // Custom rule, defined below
    'email' => 'required|email',
    'checkbox' => 'bool'
];

// Your error messages on your language
$messages = array (
    'name' => array (
        'required' => 'Поле обязательно для заполнения',
        'min' => 'Minimum required 3 characters',
        'max' => 'Maximal zulässige fünfzehn Zeichen',
        'equal' => 'Значение должно равняться - Awesome'
    ),
    'password' => array (
        'required' => 'Поле обязательно для заполнения',
        'min' => 'Minimalement acceptables 3 caractères',
        'custom_equal' => 'Кастомное сообщение для правила custom_equal'
    ),
    'checkbox' => array (
        'bool' => 'Вы не выставили галочку!'
    )
);

$validator = new \Validatr\Validator();

// Adding custom rule
$validator->addRule('custom_equal', function($dataValue, $ruleValue){
    return ($dataValue == $ruleValue) ? true : false;
});

$result = $validator->validate($_POST, $rules, $messages);

echo "";
print_r($result);
echo "";
```

### Set messages

[](#set-messages)

#### //Todo

[](#todo)

### Return Values

[](#return-values)

Method `validate()` returns one of two types:

AN ARRAY containing in keys names of form fields and in values nested associative array containing in keys validation rules and in values error messages. (See below example).

or

A BOOLEAN value of TRUE if the validation was successful.

**Return values example:**

The result may be (if all fields were sent empty):

```
Array
(
    [name] => Array
        (
            [required] => Поле обязательно для заполнения
            [min] => Minimum required 3 characters
            [equal] => Значение должно равняться - Boss
        )

    [password] => Array
        (
            [required] => Поле обязательно для заполнения
            [min] => Minimalement acceptables 3 caractères
        )

    [email] => Array
        (
            [required] => This field is required
            [email] => Invalid email address
        )

    [checkbox] => Array
        (
            [bool] => Вы не выставили галочку!
        )

)

```

Or if all fields was validated successfully:

```
1
```

### Available rules:

[](#available-rules)

```
- required  // Checks if field's value is not empty
- min       // Checks if the number of characters of field's value not less than rule value (UTF-8)
- max       // Checks if the number of characters of field's value not greater than rule value (UTF-8)
- email     // Checks if field's value is a valid email adress
- numeric   // Checks if field contains only numeric value
- bool      // Checks if field's value is boolean
- alpha     // Checks if field's value contains only alphabetic characters (UTF-8)
- alnum     // Checks if field's value contains only alphabetic and numeric characters (UTF-8)
- alnumWith // Checks if field's value contains only alphabetic and numeric characters (UTF-8) and some else custom characters
- in        // Checks if value is included in the given list of values.
- notIn     // Checks if value is not included in the given list of values.
- equal     // checks if value is equal to rule value (Strict or not)
- notEqual  // checks if value is bot equal to rule value (Strict or not)

```

### Creating your own validating rules

[](#creating-your-own-validating-rules)

For creating your own validating rules use addRule method.

```
// Lets create our own 'equal' rule.

$data = array (
    'name' => 'ok'
);

$rules = array(
    'name' => 'custom_equal:OK:strict:upper'
);

$messages = array(
    'name' => array(
        'custom_equal' => 'The value must be equal "ok"'
    )
);

// The callback function may receives three arguments:
// 1st arg - field value - 'ok' (From $data)
// 2nd arg - rule value - 'OK' (From $rules 2nd param)
// 3rd arg - additional params - array (From $rules starting 3nd and more params)

// $params in this example is an array - array('strict', 'upper'); But not used
// It should return a boolean value indicating whether the value is valid.
$validator->addRule('custom_equal', function($dataValue, $ruleValue, $params){
    return ($dataValue == $ruleValue) ? true : false;
});

$result = $validator->validate($data, $rules, $messages);
```

Contributing
------------

[](#contributing)

1. Fork it
2. Create your feature branch (git checkout -b my-new-feature)
3. Make your changes
4. Write the unit tests for your new feature (phpunit)
5. Commit your changes (git commit -am 'Add some feature')
6. Push to the branch (git push origin my-new-feature)
7. Create new Pull Request

Versioning
----------

[](#versioning)

Validatr is maintained under the Semantic Versioning guidelines. Sometimes we screw up, but we'll adhere to these rules whenever possible.

Releases will be numbered with the following format:

```
..

```

And constructed with the following guidelines:

- Breaking backward compatibility bumps the major while resetting minor and patch
- New additions without breaking backward compatibility bumps the minor while resetting the patch
- Bug fixes and misc changes bumps only the patch

For more information on SemVer, please visit .

Brazenly copied from [Bootstrap's README.md](https://github.com/twbs/bootstrap#versioning "Bootstrap versioning") =)

Authors
-------

[](#authors)

Alex D.

---

Inspired by:

-
-
-
-
-

Copyright and License
---------------------

[](#copyright-and-license)

Copyright 2016 Alex D, licensed under the [MIT](http://opensource.org/licenses/MIT "Bootstrap versioning").

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Every ~89 days

Recently: every ~201 days

Total

10

Last Release

3689d ago

Major Versions

v0.1.5 → v1.0.0-beta2014-01-27

v1.0.1-rc → v2.0.0-beta2014-03-26

v2.0.0-beta → v3.0.0-alpha2016-04-06

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.0

v3.0.0-alphaPHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/131932?v=4)[boomerang](/maintainers/boomerang)[@boomerang](https://github.com/boomerang)

---

Top Contributors

[![booomerang](https://avatars.githubusercontent.com/u/3165820?v=4)](https://github.com/booomerang "booomerang (52 commits)")

---

Tags

phpvalidatorform validatorvalidatr

### Embed Badge

![Health badge](/badges/boomerang-validatr/health.svg)

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

###  Alternatives

[runz0rd/mapper-php

Model mapping, unmapping and validation

17451.9k2](/packages/runz0rd-mapper-php)

PHPackages © 2026

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