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

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

whoa-php/validation
===================

Validation framework.

049PHP

Since Jul 21Pushed 3y agoCompare

[ Source](https://github.com/whoa-php/validation)[ Packagist](https://packagist.org/packages/whoa-php/validation)[ RSS](/packages/whoa-php-validation/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5bc1f512de10abd2b02aadf58cc7494e12e3e6785e745ab11c3b9518a59f553b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f77686f612d7068702f76616c69646174696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/whoa-php/validation/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/d51e0f3a16822a727f7ddfe41c623fbb2e5115bdc1d738515c7a750bba587709/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f77686f612d7068702f76616c69646174696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/whoa-php/validation/?branch=master)[![Build Status](https://camo.githubusercontent.com/f21894dc252b51534fa776621748cf9899b38626b8790bccac80ca320a2f0d81/68747470733a2f2f7472617669732d63692e6f72672f77686f612d7068702f76616c69646174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/whoa-php/validation)[![License](https://camo.githubusercontent.com/d10a8c492e500ec7070a9c5ddd3ceb413d0f4af1fda91421a9ae92cc1a01de09/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77686f612d7068702f76616c69646174696f6e2e737667)](https://packagist.org/packages/whoa-php/validation)

This validation library fast, easy to use yet very powerful and flexible solution. Unlike many other libraries it does not try to give you 'validation rules' for all possible cases because those implementations might not fit your requirements and using such libraries is a pain. Instead it provides an extremely simple way of adding custom validation rules.

Also it supports caching of validation rules which makes it very fast. Custom error codes and messages are supported as well. Error messages could be customized/localized and support `placeholders`.

Usage sample

```
$validator = v::validator([
    'sku'           => r::required(r::sku()),
    'amount'        => r::required(r::amount(5)),
    'delivery_date' => r::nullable(r::deliveryDate()),
    'email'         => r::email(),
    'address1'      => r::required(r::address1()),
    'address2'      => r::address2(),
    'accepted'      => r::required(r::areTermsAccepted()),
]);

$input = [
    'sku'    => '...',
    'amount' => '...',
    ...
];

if ($validator->validate($input)) {
    // use validated/converted/sanitized inputs
    $validated = $validator->getCaptures();
} else {
    // print validation errors
    $errors = $validator->getErrors();
}
```

Full sample code [is here](/sample).

As you can see such custom rules as `sku`, `amount`, `deliveryDate`, `address1`, `address2` and `areTermsAccepted` could be perfectly combined with built-in `required` and `nullable`. It makes the rules reusable in `CREATE` and `UPDATE` operations where typically inputs are required on creation and optional on update.

How easy to write those rules? Many could be made from built-in ones below (e.g. `amount`, `address1`, `address2` and `areTermsAccepted`)

> `equals`, `notEquals`, `inValues`, `lessThan`, `lessOrEquals`, `moreThan`, `moreOrEquals`, `between`, `stringLengthBetween`, `stringLengthMin`, `stringLengthMax`, `regexp`, `nullable`, `stringToBool`, `stringToDateTime`, `stringToFloat`, `stringToInt`, `stringArrayToIntArray`, `andX`, `orX`, `ifX`, `success`, `fail`, `required`, `enum`, `filter`, `isArray`, `isString`, `isBool`, `isInt`, `isFloat`, `isNumeric`, `isDateTime`

```
class Rules extends \Whoa\Validation\Rules
{
    public static function sku(): RuleInterface
    {
        return static::stringToInt(new IsSkuRule());
    }

    public static function amount(int $max): RuleInterface
    {
        return static::stringToInt(static::between(1, $max));
    }

    public static function deliveryDate(): RuleInterface
    {
        return static::stringToDateTime(DateTime::ISO8601, new IsDeliveryDateRule());
    }

    public static function email(): RuleInterface
    {
        return static::isString(
            static::filter(FILTER_VALIDATE_EMAIL, null, Errors::IS_EMAIL, static::stringLengthMax(255))
        );
    }

    public static function address1(): RuleInterface
    {
        return static::isString(static::stringLengthBetween(1, 255));
    }

    public static function address2(): RuleInterface
    {
        return static::nullable(static::isString(static::stringLengthMax(255)));
    }

    public static function areTermsAccepted(): RuleInterface
    {
        return static::stringToBool(static::equals(true));
    }
}
```

Custom rule such as `IsSkuRule` might require quering database and could be added with minimal overhead

```
class IsSkuRule extends ExecuteRule
{
    public static function execute($value, ContextInterface $context): array
    {
        $pdo   = $context->getContainer()->get(PDO::class);
        $isSku = ...;

        return $isSku === true ?
            self::createSuccessReply($value) :
            self::createErrorReply($context, $value, Errors::IS_VALID_SKU);
    }
}
```

When validator is created a developer can pass [PSR Container](http://www.php-fig.org/psr/psr-11/) with custom services and have access to this container from validation rules. Thus validation could be easily integrated with application logic.

**[Sample application](/sample)**

#### Installation

[](#installation)

```
$ composer require whoa-php/validation
```

> Note: for message translation PHP-intl is needed.

#### Issues

[](#issues)

Any related issues please send to [whoa](https://github.com/whoa-php/validation).

#### Testing

[](#testing)

```
$ composer test
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 99.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.

### Community

Maintainers

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

---

Top Contributors

[![neomerx](https://avatars.githubusercontent.com/u/10420662?v=4)](https://github.com/neomerx "neomerx (736 commits)")[![dreamsbond](https://avatars.githubusercontent.com/u/26112605?v=4)](https://github.com/dreamsbond "dreamsbond (3 commits)")

### Embed Badge

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

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

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