PHPackages                             lemmon/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. lemmon/validator

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

lemmon/validator
================

A lightweight, fluent validation library for PHP.

v0.17.0(3w ago)5620↑36.7%1MITPHPPHP ^8.3CI passing

Since Sep 5Pushed 3w agoCompare

[ Source](https://github.com/lemmon/validator-php)[ Packagist](https://packagist.org/packages/lemmon/validator)[ Docs](https://github.com/lemmon/validator-php)[ RSS](/packages/lemmon-validator/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (23)Versions (20)Used By (1)

Lemmon Validator
================

[](#lemmon-validator)

[![CI](https://github.com/lemmon/validator-php/actions/workflows/ci.yml/badge.svg)](https://github.com/lemmon/validator-php/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/2e5bfe0919c8545956ff41245a87c756a4093205bf2f49a345115f6dd0c521e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c656d6d6f6e2f76616c696461746f722e737667)](https://packagist.org/packages/lemmon/validator)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Lemmon Validator is a PHP library with no third-party Composer dependencies for validating and transforming scalar values, indexed arrays, and nested schemas for associative arrays or `stdClass`objects through a fluent API. It combines form-safe coercion, ordered pipelines, and structured errors for exception and non-exception workflows.

Note

Lemmon Validator is pre-1.0 and under active development. Minor releases may contain breaking changes; review the [changelog](CHANGELOG.md) before upgrading.

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

[](#installation)

```
composer require lemmon/validator
```

**Requirements:** PHP 8.3 or higher with the `mbstring` extension

Quick Start
-----------

[](#quick-start)

Validators accept `null` by default. Use `required()` when a value must be present.

```
use Lemmon\Validator\ValidationException;
use Lemmon\Validator\Validator;

$input = [
    'name' => 'Ada Lovelace',
    'age' => '36',
    'email' => 'ada@example.com',
];

$userSchema = Validator::isAssociative([
    'name' => Validator::isString()
        ->pipe('trim')
        ->notEmpty()
        ->required(),
    'age' => Validator::isInt()
        ->coerce()
        ->min(18), // Optional; "36" becomes 36
    'email' => Validator::isString()
        ->pipe('trim')
        ->email()
        ->required(),
]);

// Non-exception workflow
[$valid, $user, $errors] = $userSchema->tryValidate($input);
if (!$valid) {
    foreach ($errors as $error) {
        echo $error->getPath() . ': ' . $error->getMessage() . PHP_EOL;
    }
}

// Exception workflow
try {
    $user = $userSchema->validate($input);
} catch (ValidationException $exception) {
    $allErrors = $exception->getErrors();
    $emailErrors = $exception->getErrors('email');
}
```

Features
--------

[](#features)

- **No third-party Composer dependencies** — the runtime depends only on PHP and `mbstring`
- **Strict runtime type validation** for strings, integers, floats, booleans, indexed arrays, associative arrays, and `stdClass` objects; conversions are opt-in through `coerce()`
- **Form-safe optional fields** — validators accept `null` unless `required()`; numeric, boolean, and container coercion turns an empty string into `null`, while strings can opt in with `nullifyEmpty()`
- **Predictable processing** — pipeline steps execute in chain order, then `default()` and `required()`resolve the final value
- **Composable schemas** — validate nested data, omit undeclared fields by default, or retain them explicitly with `passthrough()`
- **Structured errors** — stable codes, dotted display paths, exact path segments, messages, and parameters support programmatic handling, i18n, path filtering, and JSON serialization
- **Extensible rules** — use PHP callables with `transform()`, `pipe()`, and `satisfies()`, or compose validators with logical combinators

Philosophy
----------

[](#philosophy)

Lemmon Validator focuses on core validation and predictable schema behavior rather than reimplementing every specialized rule. Its transformation and custom-validation methods accept ordinary PHP callables, so application-specific behavior can be composed without framework integrations or custom validator subclasses.

Documentation
-------------

[](#documentation)

### Getting Started

[](#getting-started)

- [Installation &amp; Setup](docs/getting-started/installation.md)
- [Basic Usage](docs/getting-started/basic-usage.md)
- [Core Concepts](docs/getting-started/core-concepts.md)

### Validation Guides

[](#validation-guides)

- [String Validation](docs/guides/string-validation.md) — Email, URL, patterns, length constraints
- [Numeric Validation](docs/guides/numeric-validation.md) — Integers, floats, ranges, constraints
- [Array Validation](docs/guides/array-validation.md) — Indexed arrays and item validation
- [Object &amp; Schema Validation](docs/guides/object-validation.md) — Complex nested structures
- [Custom Validation](docs/guides/custom-validation.md) — User-defined functions and business logic
- [Error Handling](docs/guides/error-handling.md) — Working with validation errors

### Factory Reference

[](#factory-reference)

- [Validator Factory](docs/api-reference/validator-factory.md)

### Examples

[](#examples)

- [Form Validation](docs/examples/form-validation.md)

### For AI Agents

[](#for-ai-agents)

- [`llms.txt`](llms.txt) — Technical specification with API signatures, parameters, and core behavior

Security
--------

[](#security)

Please report suspected vulnerabilities privately by following the [Security Policy](SECURITY.md). Do not disclose security issues in the public issue tracker.

Contributing
------------

[](#contributing)

Contributions are welcome. Read the [Contributing Guide](CONTRIBUTING.md), or [open an issue](https://github.com/lemmon/validator-php/issues) to report a bug or propose an improvement.

License
-------

[](#license)

Lemmon Validator is licensed under the [MIT License](LICENSE).

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance95

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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

Recently: every ~35 days

Total

19

Last Release

25d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/69d2fc0d66f2e8e99490f3781a67d2af0d6ca9cb3e48db4a6199336344d4310c?d=identicon)[lemmon](/maintainers/lemmon)

---

Top Contributors

[![lemmon](https://avatars.githubusercontent.com/u/251591?v=4)](https://github.com/lemmon "lemmon (118 commits)")

---

Tags

data-validationlibraryphpschema-validationtype-coercionvalidationvalidatorschemavalidatorvalidationzodvalibot

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

6.0k40.8M433](/packages/respect-validation)[opis/json-schema

Json Schema Validator for PHP

65446.2M367](/packages/opis-json-schema)[vlucas/valitron

Simple, elegant, stand-alone validation library with NO dependencies

1.6k4.7M144](/packages/vlucas-valitron)[intervention/validation

Additional validation rules for the Laravel framework

6837.4M22](/packages/intervention-validation)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2442.4M9](/packages/laravel-validation-rules-credit-card)[particle/validator

Flexible and highly usable validation library with no dependencies.

2522.2M10](/packages/particle-validator)

PHPackages © 2026

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