PHPackages                             djordje/li3\_validators - 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. djordje/li3\_validators

ActiveLithium-library[Validation &amp; Sanitization](/categories/validation)

djordje/li3\_validators
=======================

Collection of lithium validators

2672PHP

Since Jul 12Pushed 12y ago1 watchersCompare

[ Source](https://github.com/djordje/li3_validators)[ Packagist](https://packagist.org/packages/djordje/li3_validators)[ RSS](/packages/djordje-li3-validators/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (2)

Collection of reusable validators for [Lithium PHP Framework](https://github.com/UnionOfRAD/lithium)
====================================================================================================

[](#collection-of-reusable-validators-for-lithium-php-framework)

---

Table of content:
-----------------

[](#table-of-content)

- **[Instalation and usage](#installation-and-usage)**
- **[Custom validators:](#custom-validators)**
    - [Unique](#unique-validator)
    - [Confirm](#confirm-validator)
    - [Dependencies](#dependencies-validator)
    - [Compare with old db value](#compare-with-old-db-value-validator)
    - [Conditional in range](#conditional-in-range-validator)
- **[Overridden validators:](#overridden-validators)**
    - [Email](#email-validator)
- **[Eval comparation builder](#eval-comparation-builder)**
- **[Project status](#project-status)**

Installation adn usage:
-----------------------

[](#installation-adn-usage)

**Git clone:**

```
	cd path/to/libraries
	git clone git://github.com/djordje/li3_validators.git

```

**Or trough *composer*:**

Add this to your `composer.json` file:

```
	{
		"minimum-stability": "dev",
		"require": {
			"djordje/li3_validators": "dev-master"
		}
	}

```

After either of these two steps open `app/config/bootstrap/libraries.php` with your editor and add this to bootom of the file:

`Libraries::add('li3_validators')`

Now you can use this validators in your model just as any other bundled or added validator!

---

Custom validators:
------------------

[](#custom-validators)

###### Unique validator

[](#unique-validator)

**Name:** `'unique'`

Ensure that entered value is unique in database. If `'events'` is *update* do query with provided options

**Options:**

`'key'` string - Database table key that will be used as condition key if `'events'` is update, by default `'id'`

`'keyValue'` string - Setup key value if you don't want to fetch it from `'values'` field, by default `null`which means that field fetch value of `$options['values']['id']` if you don't change `'key'`

---

###### Confirm validator

[](#confirm-validator)

**Name:** `'confirm'`

Confirm that this field is equal to field against we compare.

**Options:**

`'strategy'` string (direct|password) - Default is `'direct'` which means we compare value against desired field directly `'string' === 'string'`. If we set this to `'password'` validator use `Password::check()` for comparing value against desired field

`'against'` string - By default this is `null` which means we will compare this field against same named field with `confirm_` prefix, eg. `email` against `confirm_email`, or we can set field name against we want to compare

---

###### Dependencies validator

[](#dependencies-validator)

**Name:** `'dependencies'`

Check field dependencies. Evaluate conditions to see if all dependencies are correct

**Options:**

`'conditions'` array - [Eval comparation builder](#eval-comparation-builder) compatible conditions array

Example:

```
	$options = array('conditions' => array(
		array('gender', '===', 'M')
	));
```

This field will require `'gender'` field equal to `'M'`

---

###### Compare with old db value validator

[](#compare-with-old-db-value-validator)

**Name:** `'compareWithOldDbValue'`

Compare value with existing value in database

**Options:**

`'strategy'` string (direct|password) - Default is `'direct'` which means we compare value against desired field directly `'string' === 'string'`. If we set this to `'password'` validator use `Password::check()` for comparing value against desired field

`'findBy'` string - Field name that will be used as condition for finding original value, default is `'id'`

`'field'` string - Original field name

Example:

```
	$options = array(
		'strategy' => 'password',
		'field' => 'password'
	);
```

This validator will assume that value of this field, for example `'old_password'` is equal to the value of `'password'` field where `'id'` is equal to current `'id'`

---

###### Conditional in range validator

[](#conditional-in-range-validator)

**Name:** `'condtionalInRange'`

This validator is very similar to Lithium's `'inRange'` validator, but require conditions to be `true`as well

**Options:**

`'upper'` integer

`'lower'` integer

`'conditions'` array - [Eval comparation builder](#eval-comparation-builder) compatible conditions array

Example:

```
	$options = array(
		'lower' => 169, 'upper' => '206',
		'conditions' => array(
        	array('gender', '===', 'M')
        )
	);
```

This assume that value of this field (for example `'height'`) is greater than 169 and smaller than 206 just if `'gender'` field exists and is equal to `'M'`

---

---

Overridden validators:
----------------------

[](#overridden-validators)

###### Email validator

[](#email-validator)

**Name:** `'email'`

**Options:**

`'pattern'` mixed (false|regex) - If `false` use php `filter_var()` function (default in Lithium) to check value, or `regex` to match against.

`'mx'` boolean that enable validator to check if MX DNS record exists

*You can achieve lithium's default behavior with **options** `'mx' => false, 'pattern' => false`.*

By default this filter check against custom regex that doesn't match all [RFC 5322](http://tools.ietf.org/html/rfc5322) valid emails, but will match against most correct emails, and doesn't check domain against MX DNS record. `'mx' => false, 'pattern' => '/^[a-z0-9][a-z0-9_.-]*@[a-z0-9.-]{3,}\.[a-z]{2,4}$/i'`

---

---

Eval comparation builder:
-------------------------

[](#eval-comparation-builder)

`li3_validators\extensions\util\EvalComparation::build(array $options)`

**Options:**

`conditions` array - This array will be converted to eval string

`values` array - Associative array of values that will be used in generated condition

Best way to understand this utility method is example:

```
	$options = array(
		'conditions' => array(array('name', '===', 'diff_test_name')),
		'values' => array('name' => 'test_name')
	);

	$eval_one = EvalComparation::build($options); // 'return (('test_name' === 'diff_test_name'));'

	$options = array(
		'conditions' => array(
			array('name', '===', 'diff_test_name'), '||', array('name', '===', 'test_name')
		),
		'values' => array('name' => 'test_name')
	);

	$eval_two = EvalComparation::build($options); // 'return (('test_name' === 'diff_test_name') || ('test_name' === 'test_name'));'
```

`eval($eval_one)` will evaluate `false`

`eval($eval_two)` will evaluate `true`

You can build nested conditions as well:

```
	$options = array(
		'conditions' => array(
			array('name', '===', 'diff_test_name'), '&&',
			array(
				array('other_field', '===', null), '||', array('other_field', '===', 'correct')
			)
		),
		'values' => array('name' => 'test_name', 'other_field' => 'other_field_val')
	);

	$eval_tree = EvalComparation::build($options);
	// 'return (('test_name' === 'diff_test_name') && (('other_field_val' === null) || ('other_field_val' === 'correct')));'
```

---

Project status
--------------

[](#project-status)

\[[![Build Status](https://camo.githubusercontent.com/ac49ea2667b362975656a0fcfcb3e717685f511f9e7617cf6171f46a01f7ab42/68747470733a2f2f7472617669732d63692e6f72672f646a6f72646a652f6c69335f76616c696461746f72732e706e673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/ac49ea2667b362975656a0fcfcb3e717685f511f9e7617cf6171f46a01f7ab42/68747470733a2f2f7472617669732d63692e6f72672f646a6f72646a652f6c69335f76616c696461746f72732e706e673f6272616e63683d6d6173746572)\] ([https://travis-ci.org/djordje/li3\_validators](https://travis-ci.org/djordje/li3_validators)) \[[![project status](https://camo.githubusercontent.com/7ea3e5061b18c522494162fbb9ca8352ede4cc50522b41603750d43a68daee76/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f646a6f72646a652f6c69335f76616c696461746f72732e706e67)](https://camo.githubusercontent.com/7ea3e5061b18c522494162fbb9ca8352ede4cc50522b41603750d43a68daee76/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f646a6f72646a652f6c69335f76616c696461746f72732e706e67)\] ([http://stillmaintained.com/djordje/li3\_validators](http://stillmaintained.com/djordje/li3_validators))

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/936366059f593fa9a53c2d9803e62c9046796ad007970deb4cbca4b52dba9e93?d=identicon)[djordje](/maintainers/djordje)

---

Top Contributors

[![djordje](https://avatars.githubusercontent.com/u/1223357?v=4)](https://github.com/djordje "djordje (38 commits)")

### Embed Badge

![Health badge](/badges/djordje-li3-validators/health.svg)

```
[![Health](https://phpackages.com/badges/djordje-li3-validators/health.svg)](https://phpackages.com/packages/djordje-li3-validators)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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