PHPackages                             polycademy/validation - 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. polycademy/validation

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

polycademy/validation
=====================

Simple Extensible Validation Library for PHP.

v1.0.9(12y ago)142WTFPLPHPPHP &gt;=5.3.0

Since Jan 5Pushed 12y ago3 watchersCompare

[ Source](https://github.com/Polycademy/PHP-Validation)[ Packagist](https://packagist.org/packages/polycademy/validation)[ Docs](https://github.com/Polycademy/PHP-Validation)[ RSS](/packages/polycademy-validation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (11)Used By (0)

Validation Library
==================

[](#validation-library)

A simple, extensible validation library for PHP with support for filtering and validating any input array. Provides a more concise interface than the upstream fork.

0.0 Table of Contents
---------------------

[](#00-table-of-contents)

- Introduction
- Examples
- Rule Reference
- Installation

1.0 Introduction
----------------

[](#10-introduction)

This library provides a simple way to validate an input array against a set of rules. Input could come from $\_POST or any other data source.

Each field can have its own label, pre-filters and rules applied to it. Rules extend a very simple interface, making adding custom rules very easy. The Validator object itself can be executed multiple times against different datasets, making it very useful for processing dynamic data.

You can easily extend this validator by simply adding more rules by extending "\\Polycademy\\Validation\\Rule". Make sure to check out the source code!

2.0 Examples
------------

[](#20-examples)

You can add rules and filters individually!

```
use Polycademy\Validation\Validator;
use Polycademy\Validation\Rule;

$validator = new Validator();
$validator
	->set_label('name', 'first name')
	->set_label('email', 'email address')
	->set_label('password2', 'password confirmation')
	->add_filter('name', 'trim')
	->add_filter('email', 'trim')
	->add_filter('email', 'strtolower')
	->add_rule('name', new Rule\MinLength(5))
	->add_rule('name', new Rule\MaxLength(10))
	->add_rule('email', new Rule\MinLength(5))
	->add_rule('email', new Rule\Email())
	->add_rule('password', new Rule\Matches('password2'))
;

if($validator->is_valid($_POST)) {
	print_r($validator->get_data());
} else {
	print_r($validator->get_errors());
}
```

Or you can use the setup\_rules and fluently add all the rules.

```
use Polycademy\Validation\Validator;
use Polycademy\Validation\Rule;

$validator = new Validator();

$validator->setup_rules(array(
	'name' => array(
		'set_label:Course Name',
		'NotEmpty',
		'AlphaNumericSpace',
		'MinLength:5',
		'MaxLength:50',
	),
	'starting_date' => array(
		'set_label:Starting Date',
		'Regex:/^(19|20)\d\d\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/',
	),
	'days_duration' => array(
		'set_label:Course Duration',
		'NotEmpty',
		'Number',
		'NumRange:1,200',
	),
	'times' => array(
		'set_label:Course Times',
		'NotEmpty',
		'MinLength:1',
		'MaxLength:100',
		'AlphaNumericSpace',
	),
	'number_of_applications' => array(
		'set_label:Number of Applicants',
		'Number',
		'NumRange:0,100',
	),
	'number_of_students' => array(
		'set_label:Number of Students',
		'Number',
		'NumRange:0,100',
	),
));

if(!$validator->is_valid($data)){

	//returns array of key for data and value
	$errors = $validator->get_errors();

}
```

More detailed examples can be found in ./examples.

3.0 Rule Reference
------------------

[](#30-rule-reference)

- **NotEmpty** Makes this a required field
- **Equal** Input must match provided string
- **NotEqual** Input must not match provided string
- **Matches** Input must match value of another field
- **InArray** Input must be in an array of values
- **MinLength** Input length must be greater than or equal to value
- **MaxLength** Input length must be less than or equal to value
- **ExactLength** Input length must be exactly value
- **Alpha** Input can only contain a-z characters
- **AlphaSpace** Input can only contain a-z characters and whitespace
- **AlphaNumeric** Input can contain a-z and 0-9
- **AlphaNumericSpace** Input can contain a-z and 0-9 and whitespace
- **AlphaSlug** Input can contain a-z, 0-9, - and \_
- **Regex** Input must match provided regular expression
- **Email** Input must be a valid email format
- **URL** Input must be a valid URL format
- **IP** Input must be a valid IPv4 or v6 address
- **True** Input must be true e.g. checkbox
- **Number** Input must be numeric e.g. -99 or 123.45
- **NumNatural** Input must be an integer zero or above
- **NumMin** Input value must be greater than or equal to value
- **NumMax** Input value must be less than or equal to value
- **NumRange** Input value must be between min and max values

4.0 Installation
----------------

[](#40-installation)

You can install by using Composer. Simply add this to your composer.json

```
"polycademy/validation": "*"

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% 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 ~34 days

Recently: every ~59 days

Total

10

Last Release

4572d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cac1bf212b88210ea171320885e262121d33d0f8a11b12d102d03eeee3005d8?d=identicon)[CMCDragonkai](/maintainers/CMCDragonkai)

---

Top Contributors

[![CMCDragonkai](https://avatars.githubusercontent.com/u/640797?v=4)](https://github.com/CMCDragonkai "CMCDragonkai (20 commits)")[![Dachande663](https://avatars.githubusercontent.com/u/106847?v=4)](https://github.com/Dachande663 "Dachande663 (16 commits)")

---

Tags

validationjqueryrulesmodelsservicesFormsclient-side

### Embed Badge

![Health badge](/badges/polycademy-validation/health.svg)

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

###  Alternatives

[hybridlogic/validation

A simple, extensible validation library for PHP with support for filtering and validating any input array along with generating client side validation code.

641.1k](/packages/hybridlogic-validation)[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

54013.2M450](/packages/nette-forms)[proengsoft/laravel-jsvalidation

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

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[karser/karser-recaptcha3-bundle

Google ReCAPTCHA v3 for Symfony

1862.4M7](/packages/karser-karser-recaptcha3-bundle)[pear/html_quickform2

Provides methods to create, validate and render HTML forms in PHP.

24498.9k2](/packages/pear-html-quickform2)[sheadawson/silverstripe-zenvalidator

Faster, easier client and server-side form validation for SilverStripe

5778.4k2](/packages/sheadawson-silverstripe-zenvalidator)

PHPackages © 2026

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