PHPackages                             kilbiller/jarvis - 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. kilbiller/jarvis

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

kilbiller/jarvis
================

A simple but powerful way to validate data in PHP.

v0.1.4(5y ago)05.9k↑55.6%MITPHPPHP &gt;=7.0

Since May 12Pushed 5y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (16)Used By (0)

Jarvis
======

[](#jarvis)

[![CircleCI](https://camo.githubusercontent.com/a7043768dc723f5da0eee439608435150e5f059f17512bfd976b0efdf25aaf74/68747470733a2f2f636972636c6563692e636f6d2f67682f6b696c62696c6c65722f6a61727669732e7376673f7374796c653d736869656c6426636972636c652d746f6b656e3d63386365343435363934623331343632663561356635653364653433313235653663376664383762)](https://circleci.com/gh/kilbiller/jarvis)[![codecov](https://camo.githubusercontent.com/dcfbf50dcce953fb8ac3af7f03997870837c57390bc1f6be1acabdd48eec1c0c/68747470733a2f2f636f6465636f762e696f2f67682f6b696c62696c6c65722f6a61727669732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/kilbiller/jarvis)

A simple but powerful way to validate data in PHP.

Requires php &gt;= 7.0

Why ?
-----

[](#why-)

I needed to be able to make complex validation logic easily and to get a nicely formatted array with the validation errors associated with their keys. I couldn't find anything that satisfied these requirements so I made Jarvis.

Features
--------

[](#features)

- Fluent interface
- Treats custom validation logic as first class citizen. They're just functions !!
- Get validation errors in a simple array, each error is associated to the input name. Only the first error for each field is kept.

Api
---

[](#api)

### Validator

[](#validator)

```
->addRule($key: string, $validationFunction: Function | [$validationFunction: Function], $message: string): void
$key: Can be nested (i.e. 'user.firstname').
$validationFunction: Can accept two parameter: the value corresponding to the key currently validated and the whole array. Should return a boolean.
$message: The error message, ${key} will be replaced by the key. Default message is : '${key} is not valid.'

->validate($dataToValidate: array): boolean

->getErrors(): array
->getErrors($dataToValidate: array): array

```

Example
-------

[](#example)

```
use Jarvis\Validator;
use function Jarvis\rules\{between, lengthBetween, noWhiteSpace};

$data = ['age' => 45, 'firstname' => 'Jonathan', 'lastname' => 'Blow'];
$data2 = ['age' => 53, 'firstname' => 'Johnny', 'lastname' => 'Depp'];

$validator = (new Validator())
->addRule('age', between(15, 48));
->addRule('firstname', function ($firstname) {
	return $firstname === 'Jonathan';
}, '${key} is not Jonathan.');
->addRule('lastname', [noWhiteSpace(), lengthBetween(0, 50)]),

$validator->validate($data); // -> true
$validator->getErrors(); // -> []

$validator->validate($data2); // -> false
$validator->getErrors(); // -> ['age' => 'age is not valid.', 'firstname' => 'firstname is not Jonathan.']
```

### Built-in rules

[](#built-in-rules)

- between(min, max)
- isBoolean()
- isDate(format = 'Y-m-d')
- isJson()
- isNull()
- isNumber()
- isPositive()
- isUppercase()
- isString()
- lengthBetween(min, max)
- matchRegex(regex)
- notEmpty()
- noWhiteSpace()
- oneOf(...$functions)

### Pro tips

[](#pro-tips)

There is two way to apply muliple validation rules for a single key :

- Use an array of validation functions -&gt; this way you can only use a single error message
- Call addRule multiple times with the same key -&gt; this way you can be more precise with your error messages

All function are curried so you can built-in rules without any argument rather than '\\Jarvis\\rules\\isNumber'.

```
use Jarvis\Validator;
use function Jarvis\rules\isNumber;

$validator = (new Validator())
->addRule('age', isNumber());
```

### Todo

[](#todo)

- Accept objects
- Add more default rules

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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.

###  Release Activity

Cadence

Every ~85 days

Recently: every ~208 days

Total

15

Last Release

2093d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3019848?v=4)[Rémy Peru](/maintainers/kilbiller)[@kilbiller](https://github.com/kilbiller)

---

Top Contributors

[![kilbiller](https://avatars.githubusercontent.com/u/3019848?v=4)](https://github.com/kilbiller "kilbiller (26 commits)")

---

Tags

phpvalidation

### Embed Badge

![Health badge](/badges/kilbiller-jarvis/health.svg)

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

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