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

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

limoncello-php/validation
=========================

Validation framework.

0.10.0(6y ago)03.2k4Apache-2.0PHPPHP &gt;=7.3.0CI failing

Since Mar 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/limoncello-php-dist/validation)[ Packagist](https://packagist.org/packages/limoncello-php/validation)[ Docs](https://github.com/limoncello-php/framework/tree/master/components/Validation)[ RSS](/packages/limoncello-php-validation/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (7)Versions (49)Used By (4)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5ba45604dc310742f7ce1650ba914d03a57f3d827d3cad62655dcc67c1904c48/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c696d6f6e63656c6c6f2d7068702d646973742f76616c69646174696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/limoncello-php-dist/validation/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/0aeb84bd16e8b7e891ec93380c016aff2459e9de127185a848331d44f5edd640/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c696d6f6e63656c6c6f2d7068702d646973742f76616c69646174696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/limoncello-php-dist/validation/?branch=master)[![Build Status](https://camo.githubusercontent.com/909181b41b41f21a8afa83742019bba4382b9845868ba2827d49b56096830c8b/68747470733a2f2f7472617669732d63692e6f72672f6c696d6f6e63656c6c6f2d7068702d646973742f76616c69646174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/limoncello-php-dist/validation)[![License](https://camo.githubusercontent.com/68b48c88c9e827c110330700319b3f9e6c0c13c22b87868ebc6ab64033c64cfa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c696d6f6e63656c6c6f2d7068702f76616c69646174696f6e2e737667)](https://packagist.org/packages/limoncello-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 \Limoncello\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 limoncello-php/validation
```

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

#### Issues

[](#issues)

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

#### Testing

[](#testing)

```
$ composer test
```

###  Health Score

30

—

LowBetter than 61% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~23 days

Recently: every ~173 days

Total

47

Last Release

2379d ago

PHP version history (4 changes)0.5.1PHP &gt;=5.6.0

0.5.4PHP &gt;=7.0.0

0.7.1PHP &gt;=7.1.0

0.10.0PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0da01dc445667261310b897ad80724e8c63130515b03159c79b1eeb2f3983c9a?d=identicon)[neomerx](/maintainers/neomerx)

---

Top Contributors

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

---

Tags

validation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k534.3M1.1k](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k163.3M572](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

6.0k40.8M429](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k41.2M166](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

65446.2M362](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

9518.1M89](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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