PHPackages                             xphoenyx/valify - 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. xphoenyx/valify

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

xphoenyx/valify
===============

A little framework for user input validation

v1.11(10y ago)2357MITPHPPHP &gt;=5.4.0

Since Apr 14Pushed 4y ago2 watchersCompare

[ Source](https://github.com/xphoenyx/valify)[ Packagist](https://packagist.org/packages/xphoenyx/valify)[ Docs](https://github.com/xphoenyx/valify)[ RSS](/packages/xphoenyx-valify/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (12)Used By (0)

***NB! This project is archived thus not maintained anymore***

Valify
======

[](#valify)

A little framework for user input validation. It is still in development, so keep an eye on commits. Inspired by [Yii2 input validation implementation](https://github.com/yiisoft/yii2/blob/master/docs/guide/input-validation.md).

Requirements
------------

[](#requirements)

You need PHP 5.4 to run this code.

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

[](#installation)

After downloading source, add next code to file, where you data is going to be validated:

```
require 'valify/Validator.php';
$validator = new Validator();
```

Framework uses namespaces, so add next line to the top of file, where validator is called:

```
use valify\Validator;
```

There is also a more straightforward way to install this framework through the compser. In your project root, issue next command in terminal:

`php composer.phar require xphoenyx/valify 1.*`

Now you are ready to validate your data.

### Hint for a MVC pattern users

[](#hint-for-a-mvc-pattern-users)

You can implement your own methods in base model class. Please investigate an example below:

```
use valify\Validator;

class Model {
    /* ... */

    protected $validator;
    // Your rules
    public $rules = [];
    // Here is stored $_POST, for example
    public $data = [];

    function __construct() {
        /* ... */
        $this->validator = new Validator();
        /* ... */
    }

    /*
     * Your other methods
     */

    public function validate() {
        return $this->validator
            ->setRules($this->rules)
            ->loadData($this->data)
            ->validate();
    }

    public function getErrors() {
        return $this->validator->getErrors();
    }
}
```

Usage
-----

[](#usage)

Usage is similar to [Yii2 input validation](https://github.com/yiisoft/yii2/blob/master/docs/guide/input-validation.md).

### Define rules

[](#define-rules)

```
$rules = [
    [['username', 'password'], 'string', 'max'=>10],
    ['email', 'email', 'message'=>'Please provide a valid email'],
    ['remember_me', 'boolean']
    /* ... */
];
```

Each validator accepts `message` parameter, which should contain an error message as string. You can access attribute name and its value in `message` by using so-called 'patterns':

```
['email', 'email', 'message'=>'{value} for attribute "{attribute}" is not a valid email'],
```

*NB! If the value is not representable as a string, value type will be shown instead of value itself*

You can also implement your own validators by extending `valify\validator\AbstractValidator` class. In this case, if you are not using composer autoloader, you should also import (require) AbstractValidator. To use own validator in rules, just define validator namespace as a validator name:

```
$rules = [
    /* ... */
    ['email', '\\examples\\ExampleValidator', 'ownProperty'=>'abc' /* ... */]
    /* ... */
];
```

Make sure your validator is loaded before defining a namespace in rules. Refer to the `valify\validators\ExampleValidator` for detailed implementation info.

### Define data to be validated

[](#define-data-to-be-validated)

Input data is expected in next format:

```
$data = [
    'username'=>'username',
    'password'=>'123qwe',
    'email'=>'address@gmail.com',
    'remember_me'=>'1',
    /* ... */
];
```

### Set rules and data

[](#set-rules-and-data)

```
$validator = new Validator();
$validator = $validator->setRules($rules)->loadData($data)
```

You can call `setrules()` and `loadData()` multiple times:

```
$validator = new Validator();
$validator = $validator
                ->setRules([...])
                ->loadData([...])
                ->setRules([...])
                ->setRules([...])
                ->loadData([...])
                ->loadData([...]);
```

### Execute validation

[](#execute-validation)

```
$isValid = $validator->validate();
```

You have an ability to perform a single value validation, without calling `setRules()` and `loadData()`:

```
$password = $_POST['password'];
$isValid = Validator::validateFor('string', $password, ['min'=>6, 'max'=>20]);
```

For multiple value validation, pass an array of desired values as a second argument:

```
$values = [
    $_POST['username'],
    $_POST['first_name'],
    $_POST['password'],
];
$isValid = Validator::validateFor('string', $values, ['min'=>3, 'max'=>30]);
```

`validateFor()` will return an object with two properties:

- `isValid` - contains boolean value;
- `lastError` - contains last validation error message;
- `errors` - contains whole error message stack for validating attribute;

### Fetch error messages

[](#fetch-error-messages)

```
if($validator->hasErrors()) {
    $errorMsgs = $validator->getErrors();
}
```

You can also get an error message of a single attribute:

```
$errorMsgForUserAttr = $validator->getError('username');
```

As each attribute can have a few error messages, `getError()` will give you the last message of the corresponding attribute error stack (array).

List of built-in validators:
----------------------------

[](#list-of-built-in-validators)

- boolean
- email
- file
- required
- string
- url
- phone
- in
- number
- compare
- unique

For detailed parameter description of each validator, see class methods in valify/validators.

Testing
-------

[](#testing)

In order to properly run unit tests, you need to specify path to the composer autoloader file. Then you just issue the `phpunit` command in terminal under `valify` (component root) directory.

Examples
--------

[](#examples)

Check index.php in `examples` directory to view framework in action.

All bug and issue reports are welcome as well as improvement proposals. Enjoy.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity65

Established project with proven stability

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 ~12 days

Recently: every ~21 days

Total

10

Last Release

3938d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e61c115175bb6fe1d2e92f406edb5408400cc26cd7a2d8bdeadaf6a65370dc8e?d=identicon)[xphoenyx](/maintainers/xphoenyx)

---

Tags

validatorvalidationvalidate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/xphoenyx-valify/health.svg)

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[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)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[sadegh19b/laravel-persian-validation

A comprehensive Laravel validation package for Persian text, numbers, dates, and Iranian national identifiers

18293.8k1](/packages/sadegh19b-laravel-persian-validation)[awurth/slim-validation

A wrapper around the respect/validation PHP validation library for easier error handling and display

65378.4k9](/packages/awurth-slim-validation)[romeoz/rock-validate

Flexible validator for PHP with I18N.

251.7k6](/packages/romeoz-rock-validate)

PHPackages © 2026

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