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

Abandoned → [azi/envalid](/?search=azi%2Fenvalid)Library

azi/validator
=============

Server side user input validation library

2.0(10y ago)211899[1 PRs](https://github.com/azeemhassni/Validator/pulls)MITPHPPHP &gt;=5.4

Since Apr 8Pushed 9y ago4 watchersCompare

[ Source](https://github.com/azeemhassni/Validator)[ Packagist](https://packagist.org/packages/azi/validator)[ RSS](/packages/azi-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

This Package is Abandoned in favor if
==============================================================================

[](#this-package-is-abandoned-in-favor-if-httpsgithubcomazeemhassnienvalid)

PHP Server Side Form Validation
-------------------------------

[](#php-server-side-form-validation)

[![Build Status](https://camo.githubusercontent.com/2a639cacc5bb9ebc4b7eac11aba961886681da6d2d62a8186bdffa98ea655cb4/68747470733a2f2f7472617669732d63692e6f72672f617a65656d686173736e692f76616c696461746f722e7376673f6272616e63683d76322e30)](https://travis-ci.org/azeemhassni/validator)[![Codacy Badge](https://camo.githubusercontent.com/afa13a303181e6a80a2bbc519a4f60f9919668b2eeeb8eda233d907a0c926c47/68747470733a2f2f7777772e636f646163792e636f6d2f70726f6a6563742f62616467652f3333336539663166346162663466363139356534613939623161326535373636)](https://www.codacy.com/app/azibaloch247/validator)[![Latest Stable Version](https://camo.githubusercontent.com/ce2937a706c7027b358e5775a9a6196f9482624c9c4317869820a059288118c4/68747470733a2f2f706f7365722e707567782e6f72672f617a692f76616c696461746f722f762f737461626c652e737667)](https://packagist.org/packages/azi/validator) [![Total Downloads](https://camo.githubusercontent.com/c44f497c3766ce6707b0b3f6cb28c6e04aca1d786cc5420e0c3d3a3baefc67c3/68747470733a2f2f706f7365722e707567782e6f72672f617a692f76616c696461746f722f646f776e6c6f6164732e737667)](https://packagist.org/packages/azi/validator) [![Latest Unstable Version](https://camo.githubusercontent.com/593f834adde46f38a7abcc433c717740b826dd8fd9c461aece8a26cc304a5b95/68747470733a2f2f706f7365722e707567782e6f72672f617a692f76616c696461746f722f762f756e737461626c652e737667)](https://packagist.org/packages/azi/validator) [![License](https://camo.githubusercontent.com/1ceb6109ee7ac012589d7329526de98de85e80cc75f6a75debbc02c3b94a3ad2/68747470733a2f2f706f7365722e707567782e6f72672f617a692f76616c696461746f722f6c6963656e73652e737667)](https://packagist.org/packages/azi/validator)[![Join the chat at https://gitter.im/azeemhassni/validator](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/azeemhassni/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

This is a small PHP package that makes it easy to validate forms in your project specially larger forms.

Installation Guide:
-------------------

[](#installation-guide)

You can install **Validator** either via package download from github or via composer install. I encourage you to do the latter:

```
{
  "require": {
    "azi/validator": "2.*"
  }
}
```

\##Usage to get started

- require composer autoloader

```
require 'vendor/autoload.php';
```

- Instantiate the Validator class

```
use azi\Validator;
$v = new Validator();
```

- Define Rules for each form field

```
  $rules = array(
        'name' => 'alpha|required',
        'age'  => 'num|required',
    );
```

- Run the **validator**

```
$v->validate( $_POST, $rules );
```

- check validator for errors, if validation fails redirect back to the form

```
if ( !$v->passed() ) {
        $v->goBackWithErrors();
    }
```

- show validation errors to user

```
 Name :

```

you can wrap error messages with custom HTML markup

```
  Validator::error('confirm_password', ':message');
```

Rules
-----

[](#rules)

- required
- num
- alpha
- alnum
- email
- ip
- url
- min:number
- max:number
- same:field\_name

Custom Expressions &amp; Messages
---------------------------------

[](#custom-expressions--messages)

- Custom Expressions

you can register your custom RegExp before running the validator

```
$v->registerExpression( 'cnic', '#^([0-9]{13})$#', 'Invalid CNIC number' );
```

registerExpression method takes 3 arguments

- expressionID - unique name for the expression
- pattern - the RegExp string
- message \[optional\] - the error message to be retured if the validation fails

```
Validator::registerExpression($expressionID , $pattern, $message)
```

- Custom Messages

you can also pass a custom error message with each rule

```
 $rules['full_name'] = "required--Please Enter your name";
```

Registring custom rules
-----------------------

[](#registring-custom-rules)

this weekend (15th Aug 2015) i was working on a must have feature in validator which is accepting custom rules at run time. here is how you can do it from now on.

```
$validator = new azi\validator();
$validator->addRule('isUnique', function($field, $value){
    $query = mysqli_query("SELECT * FROM users WHERE username = $value");
    if($query->affected_rows > 0) {
        return "Username '$value' already exists please try something else";
    }

    return true;
);
```

now you can use this newly registered rule.

```
$validator->validate(
    $_POST, ['username' => 'isUnique|required']
);
```

now you have so much power on your fields validation do whatever you want in Closure you passed to `Validator::addRule()` as 2nd argument.

Conditional Rules
-----------------

[](#conditional-rules)

you can spacify conditional rules for a field

```
 $rules['age'] = 'if:gender[Male](required|min:2|num)';
```

Comparison Rules
----------------

[](#comparison-rules)

you can also compare a field with another

```
  $rules['password'] = 'required|min:8';
  $rules['confirm_password'] = 'same:password';
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 91.5% 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 ~43 days

Total

4

Last Release

3928d ago

Major Versions

1.2 → 2.02015-08-16

### Community

Maintainers

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

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

---

Top Contributors

[![azeemhassni](https://avatars.githubusercontent.com/u/6503258?v=4)](https://github.com/azeemhassni "azeemhassni (97 commits)")[![farzak](https://avatars.githubusercontent.com/u/6195666?v=4)](https://github.com/farzak "farzak (4 commits)")[![jarbitlira](https://avatars.githubusercontent.com/u/3398354?v=4)](https://github.com/jarbitlira "jarbitlira (2 commits)")[![KhairJ](https://avatars.githubusercontent.com/u/12038115?v=4)](https://github.com/KhairJ "KhairJ (2 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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