PHPackages                             khalyomede/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. khalyomede/validator

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

khalyomede/validator
====================

Validate arrays.

v0.4.0(7y ago)061MITPHPPHP &gt;=7.2.0

Since Nov 9Pushed 7y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (6)Used By (0)

Validator
=========

[](#validator)

Validate arrays.

[![PHP from Packagist](https://camo.githubusercontent.com/2e56e4c5bbb74bfafcd6ff8410cfa400f43bad90c6edf02ba4f508c501d5de81/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b68616c796f6d6564652f76616c696461746f722e737667)](https://camo.githubusercontent.com/2e56e4c5bbb74bfafcd6ff8410cfa400f43bad90c6edf02ba4f508c501d5de81/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b68616c796f6d6564652f76616c696461746f722e737667) [![Packagist](https://camo.githubusercontent.com/2c3d78825fbb45750b05a54b217a3c4eee3af3ea34077bdaa5162b755e67446e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616c796f6d6564652f76616c696461746f722e737667)](https://camo.githubusercontent.com/2c3d78825fbb45750b05a54b217a3c4eee3af3ea34077bdaa5162b755e67446e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616c796f6d6564652f76616c696461746f722e737667) [![Codeship](https://camo.githubusercontent.com/e0f60b578210e91a79fdd20b93be7c6bb7394698b7983513f58b0b7354dd8612/68747470733a2f2f696d672e736869656c64732e696f2f636f6465736869702f36393262326331302d633731322d303133362d343363652d3636626334323161383438622e737667)](https://camo.githubusercontent.com/e0f60b578210e91a79fdd20b93be7c6bb7394698b7983513f58b0b7354dd8612/68747470733a2f2f696d672e736869656c64732e696f2f636f6465736869702f36393262326331302d633731322d303133362d343363652d3636626334323161383438622e737667) [![Packagist](https://camo.githubusercontent.com/8e3e07cc7963d774ed94ba476969f8e14398412a2d445ad6864eab5d2529c00f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68616c796f6d6564652f76616c696461746f722e737667)](https://camo.githubusercontent.com/8e3e07cc7963d774ed94ba476969f8e14398412a2d445ad6864eab5d2529c00f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68616c796f6d6564652f76616c696461746f722e737667)

```
$validator = new Validator([
  'name' => ['required', 'string'],
  'hobbies' => ['array'],
  'hobbies.*' => ['string']
]);

$validator->validate([
  'name' => 'John',
  'hobbies' => ['programming', 'comics', 'workout']
]);

var_dump($validator->failed()); // false
```

Summary
-------

[](#summary)

- [Installation](#installation)
- [Examples](#examples)
- [Rules](#rules)
- [Helpers](#helpers)

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

[](#installation)

In your project root:

```
composer require khalyomede\validator:0.*
```

Examples
--------

[](#examples)

- [Example 1: validating a string](#example-1-validating-a-string)
- [Example 2: validating a required element](#example-2-validating-a-required-element)
- [Example 3: add a new rule](#example-3-add-a-new-rule)
- [Example 4: check if a rule already exist or not](#example-4-check-if-a-rule-already-exist-or-not)
- [Example 5: using dot syntax to validate multiple elements](#example-5-using-dot-syntax-to-validate-multiple-elements)

### Example 1: validating a string

[](#example-1-validating-a-string)

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

use Khalyomede\Validator;
use Khalyomede\Exception\RuleNotFoundException;

$validator = new Validator([
  'name' => ['string']
]);

try {
  $validator->validate(['name' => 'John']);

  var_dump($validator->failed()); // false
}
catch( RuleNotFoundException $exception ) {
  echo "rule {$exception->getRule()} does not exists";

  exit(1);
}
```

### Example 2: validating a required element

[](#example-2-validating-a-required-element)

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

use Khalyomede\Validator;
use Khalyomede\Exception\RuleNotFoundException;

$validator = new Validator(['name' => ['required', 'string']]);

try {
  $validator->validate(['name' => 'John']);

  var_dump($validator->failed()); // false
}
catch( RuleNotFoundException $exception ) {
  echo "rule {$exception->getRule()} does not exist";

  exit(1);
}
```

### Example 3: add a new rule

[](#example-3-add-a-new-rule)

```
equire __DIR__ . '/../vendor/autoload.php';

use Khalyomede\Validator;
use Khalyomede\Exception\RuleAlreadyExistException;
use Khalyomede\Exception\RuleNotFoundException;

try {
  Validator::extends('longitude', function($value, $key, $items) {
    return is_float($value) && ($value >= -180) && ($value  ['required', 'array'],
  'sith.*' => ['string']
]);

$validator->validate([
  'sith' => ['Darth Maul', 'Darth Vador', 'Darth Sidious']
]);

var_dump( $validator->failed() ) // "false", hm... should have been true after all these guys did but anyway
```

Rules
-----

[](#rules)

- [array](#array)
- [date](#date)
- [datetime](#datetime)
- [email](#email)
- [filled](#filled)
- [integer](#integer)
- [lower](#lower)
- [present](#present)
- [required](#required)
- [same](#same)
- [slug](#slug)
- [string](#string)
- [time](#time)
- [upper](#upper)

### array

[](#array)

Validate that a key is an array.

```
$validator = new Validator([
  'hobbies' => ['array']
]);
```

### date

[](#date)

Validate that a key is filled with a valid date in format `yyyy-mm-dd` ([ISO 8601](https://www.iso.org/standard/40874.html)).

```
$validator = new Validator([
  'created_at' => ['date']
]);
```

### datetime

[](#datetime)

Validate that a key is filled with a valid date in formt `yyyy-mm-dd hh:mm:ss` ([ISO 8601](https://www.iso.org/standard/40874.html)).

```
$validator = new Validator([
  'updated_at' => ['datetime']
]);
```

### email

[](#email)

Validate that a key is filled with an email.

```
$validator = new Validator([
  'contact' => ['email']
]);
```

### filled

[](#filled)

Validate that a key is filled with a non empty value.

```
$validator = new Validator([
  'name' => ['filled']
]);
```

### integer

[](#integer)

Validate that a key is filled with an integer.

```
$validator = new Validator([
  'age' => ['integer']
]);
```

### lower

[](#lower)

Validate that a key is filled only with lowercases (non-alpha characters are allowed as well).

```
$validator = new Validator([
  'street' => ['lower']
]);
```

### present

[](#present)

Validate that a key exists.

```
$validator = new Validator([
  'lastname' => ['present']
]);
```

### required

[](#required)

Validate that a key is present. The key can be empty by the way.

```
$validator = new Validator([
  'name' => ['required']
]);
```

### same

[](#same)

Validate that two keys are the same.

```
$validator = new Validator([
  'password' => ['string', 'same:confirmation'],
  'confirmation' => ['string']
]);
```

### slug

[](#slug)

Validate that a string is a slug (only lowercases, dashes `-` allowed).

```
$validator = new Validator([
  'title' => ['slug']
]);
```

### string

[](#string)

Validate that a key is a string.

```
$validator = new Validator([
  'name' = ['string']
]);
```

### time

[](#time)

Validate that a key is filled with a time with the format `hh:mm:ss`.

```
$validator = new Validator([
  'duration' => ['time']
]);
```

### upper

[](#upper)

Validate that a string is only in uppercase.

```
$validator = new Validator([
  'name' => ['upper']
]);
```

Helpers
-------

[](#helpers)

- [extends](#extends)
- [has](#has)

### extends

[](#extends)

Add a new rule.

```
Validator::extends('jedi', function($value, $key, $items) {
  return in_array($value, ['qui-gon jinn', 'obiwan', 'luke']);
});
```

### has

[](#has)

Check if the rule already exist.

```
Validator::has('sith'); // bool(false)
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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

Total

5

Last Release

2693d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Tags

arrayphpvalidate

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[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)[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)

PHPackages © 2026

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