PHPackages                             aubind97/php-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. [Framework](/categories/framework)
4. /
5. aubind97/php-validator

ActiveLibrary[Framework](/categories/framework)

aubind97/php-validator
======================

A PHP Validator

v1.0.2(6y ago)061MITPHP

Since Mar 13Pushed 6y agoCompare

[ Source](https://github.com/Aubind97/php-validator)[ Packagist](https://packagist.org/packages/aubind97/php-validator)[ RSS](/packages/aubind97-php-validator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (4)Versions (4)Used By (0)

PHP Validator ✔️
================

[](#php-validator-️)

**php-validator** is a package to provide server-side validations

[![Build Status](https://camo.githubusercontent.com/f941856f996ce2fcddf8ebc514bf72c83a2aa335d95e380cde689edc56b8d150/68747470733a2f2f7472617669732d63692e6f72672f417562696e6439372f7068702d76616c696461746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Aubind97/php-validator)

📖 Documentation
===============

[](#-documentation)

💿 Installation
--------------

[](#-installation)

**php-validator** can be installed via `composer`, just execute the following command in your project root

```
composer require aubind97/php-validator
```

Or you can add the following input in your `composer.json` file.

```
"require": {
  "aubind97/php-validator": "^1.0"
}
```

📚 Usage
-------

[](#-usage)

> Make sure to use `composer` autoloading to load the package
> Be sure to add the `use` statement or add the namespace before `Validator`

Using **php-validator** in your projet is super simple, here is an example

```
$validator = (new Validator($_POST))
  ->email('email')
  ->length('firstname', 2, 100)
  ->length('lastname', 2, 100)
  ->length('nickname', 2, 100)
  ->required('email', 'firstname', 'lastname');
```

> We can validate `$_POST` or any other arrays

Then, you can check for validation like this

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

If there are errors, you can get errors messages with

```
$validator->getErrors();
```

Optionnally, you can pass an associative array for parameters internationalization. The key is the attribute name you passed in the Validator constructor, the value is the translation (FR example below).

```
$validator->getErrors([
  'firstname' => 'prénom'
]);
```

### Advanced features

[](#advanced-features)

You can add a filter at the validator creation, to discard not needed arguments

```
$validator = new Validator($_POST, ['firstname', 'lastname']);
```

You can also create validator with many rules, to validate all params of a model for instance, and apply rules only is the params are in the array params given at the construction

```
$validator = new Validator($_POST, ['firstname', 'lastname'], true);
```

Finally, you can pass IETF locale for internationalization (currently supports en-US, fr-FR)

```
$validator = new Validator($_POST, ['firstname', 'lastname'], true, 'fr-FR');
```

📏 Available rules
-----------------

[](#-available-rules)

Here is the list of all available validation rules

### `required`

[](#required)

Check if the requested params are given

```
$validator->required('key')
$validator->required('key1', 'key2')
```

### `dateTime`

[](#datetime)

Check if the requested param is a date that follow the specified format

```
$validator->dateTime('key') // Default format 'Y-m-d H:i:s'
$validator->dateTime('key', 'Y-m-d')
```

### `email`

[](#email)

Check if the requested param is an email

```
$validator->email('key')
```

### `exists`

[](#exists)

Check if the requested param exists in the table (in a database)

```
$validator->exists('key', 'column', 'table', $pdo) // $pdo is a \PDO connection
```

### `extension`

[](#extension)

Check if the requested param is of the specified extensions

```
$validator->extension('key', ['jpg', 'png']) // You can add the format you want
```

### `length`

[](#length)

Check if the requested param length

```
$validator->length('key', 3) // more than 3 characters
$validator->length('key', null, 10) // less than 10 characters
$validator->length('key', 3, 10) // between 3 and 10 characters
```

### `money`

[](#money)

Check if the requested param correspond to a price value

```
$validator->money('key')
```

### `notEmpty`

[](#notempty)

Check if the requested param is not empty

```
$validator->notEmpty('key')
$validator->notEmpty('key1', 'key2')
```

### `numeric`

[](#numeric)

Check if the requested param is a numeric

```
$validator->numeric('key')
```

### `slug`

[](#slug)

Check if the requested param is a slug (word separated by '-')

```
$validator->slug('key')
```

### `unique`

[](#unique)

Check if the requested param is unique in a table (in a databse)

```
$validator->unique('key', 'column', 'table', $pdo) // $pdo is a \PDO connection

// the value of 'key' is unique excluding the row with the id equal to 1
$validator->unique('key', 'column', 'table', $pdo, 1)
```

### `uploaded`

[](#uploaded)

Check if the requested param is uploaded without errors

```
$validator->('key')
```

🤝 Contributions
---------------

[](#-contributions)

This repository is maintained by @aubind97

> If you want to improve the system I'd love to merge your PR.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 62.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 ~68 days

Total

3

Last Release

2484d ago

### Community

Maintainers

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

---

Top Contributors

[![Aubind97](https://avatars.githubusercontent.com/u/23362650?v=4)](https://github.com/Aubind97 "Aubind97 (10 commits)")[![IraSkyx](https://avatars.githubusercontent.com/u/29518738?v=4)](https://github.com/IraSkyx "IraSkyx (6 commits)")

---

Tags

frameworkvalidatorvalidation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[davidepastore/slim-validation

A slim middleware for validation based on Respect/Validation

171223.7k3](/packages/davidepastore-slim-validation)[runn/validation

Runn Me! Validation and Sanitization Library

1027.6k2](/packages/runn-validation)[krzysztofrewak/laravel-oop-validator

Laravel Validator object-oriented wrapper

805.8k](/packages/krzysztofrewak-laravel-oop-validator)[marwanalsoltany/mighty

The last validation library you will ever need!

591.3k](/packages/marwanalsoltany-mighty)

PHPackages © 2026

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