PHPackages                             hstanleycrow/easyphpformvalidator - 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. hstanleycrow/easyphpformvalidator

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

hstanleycrow/easyphpformvalidator
=================================

Lightweight PHP library for validating form input with a fluent, Laravel-like rule syntax.

v2.1.0(1mo ago)029↓66.7%1MITPHPPHP ^8.2

Since Oct 29Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/hstanleycrow/EasyPHPFormValidator)[ Packagist](https://packagist.org/packages/hstanleycrow/easyphpformvalidator)[ Docs](https://github.com/hstanleycrow/EasyPHPFormValidator)[ RSS](/packages/hstanleycrow-easyphpformvalidator/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (11)Used By (1)

English | [Español](README.es.md)

EasyPHPFormValidator
====================

[](#easyphpformvalidator)

Lightweight PHP library for validating form input, with a fluent, Laravel-like rule syntax.

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Composer

The library has no runtime dependencies beyond PHP itself.

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

[](#installation)

```
composer require hstanleycrow/easyphpformvalidator
```

Quick example
-------------

[](#quick-example)

```
use hstanleycrow\EasyPHPFormValidator\Validator;
use hstanleycrow\EasyPHPFormValidator\ValidationException;

require 'vendor/autoload.php';

$data = [
    'name' => 'Harold',
    'email' => 'jeloumyfriend@gmail.com',
    'age' => '46',
];

$rules = [
    'name' => 'required|string|min:3|max:10',
    'email' => 'required|email',
    'age' => 'required|integer|min:18',
];

try {
    Validator::validate($data, $rules);
    echo 'Validation passed!';
} catch (ValidationException $e) {
    foreach ($e->getErrors() as $field => $errors) {
        foreach ($errors as $error) {
            echo "$error\n";
        }
    }
}
```

Rules for the same field are chained with `|`. Rules that take a parameter use `rule:value` (e.g. `min:3`, `in:apple,banana,orange`).

Custom error messages
---------------------

[](#custom-error-messages)

Pass a third `$messages` array keyed as `field.rule`:

```
Validator::validate($data, $rules, [
    'name.required' => 'The name field is required',
    'email.email' => 'You must provide a valid email address',
]);
```

Available rules
---------------

[](#available-rules)

RuleDescription`required`Value must be present and not an empty string.`string`Value must be a string.`integer`Value must be an integer, or a numeric string representing one.`min:value`Minimum numeric value if the input is numeric (including numeric strings like `'46'`), otherwise minimum string length.`max:value`Maximum numeric value if the input is numeric (including numeric strings like `'46'`), otherwise maximum string length.`in:a,b,c`Value must be one of the given comma-separated options.`email`Value must be a valid email address.`url`Value must be a valid `http`/`https` URL.`phone`Value must be a phone number (6 to 15 digits, optional leading `+`).`confirmed:field`Value must match `field_confirmation` in the same data array. The parameter is optional: `confirmed` alone uses the validated field itself (`password` → `password_confirmation`).`decimal:places`Value must be numeric with either no decimal part or exactly `places` decimal digits.`decimalNumber`Value must be numeric and not a whole number.`greaterThanZero`Value must be numeric and greater than zero.`nullable`Marks a field as optional: if the value is `null` or `''`, the remaining rules for that field are skipped (including `required`).`date:format`Value must be a valid date in `format` (default `Y-m-d`).`after:date`Value must be a date strictly after `date`.`afterOrEqual:date`Value must be a date on or after `date`.`before:date`Value must be a date strictly before `date`.`beforeOrEqual:date`Value must be a date on or before `date`.`fileExtension:a,b,c`Value's file extension must be one of the given options.`svphone:fix|mov`Example custom rule: validates Salvadoran landline (`fix`) or mobile (`mov`) numbers.Extending with custom rules
---------------------------

[](#extending-with-custom-rules)

Register a custom rule at runtime with `Validator::extend()`, without touching the library's source:

```
use hstanleycrow\EasyPHPFormValidator\Rules\RuleInterface;
use hstanleycrow\EasyPHPFormValidator\Validator;

class EvenNumberRule implements RuleInterface
{
    public function passes(mixed $value, array $data = []): bool
    {
        return is_numeric($value) && ((int) $value) % 2 === 0;
    }

    public function message(string $attribute): string
    {
        return "$attribute must be an even number.";
    }
}

Validator::extend('evenNumber', EvenNumberRule::class);

Validator::validate(['quantity' => 3], ['quantity' => 'evenNumber']);
// throws ValidationException: "quantity must be an even number."
```

Any rule that needs to compare against another field (like `confirmed`) receives the full submitted data array as the second argument to `passes()`.

Public methods
--------------

[](#public-methods)

### Validator

[](#validator)

MethodDescription`Validator::validate(array $data, array $rules, array $messages = []): void`Validates `$data` against `$rules`. Throws `ValidationException` if any rule fails.`Validator::extend(string $ruleName, string $ruleClass): void`Registers a custom rule class (must implement `RuleInterface`) under `$ruleName`.### ValidationException

[](#validationexception)

MethodDescription`getErrors(): array`Returns errors as `[field => [message, ...]]`.### RuleInterface

[](#ruleinterface)

MethodDescription`passes(mixed $value, array $data = []): bool`Returns whether `$value` satisfies the rule. `$data` is the full submitted data array.`message(string $attribute): string`Returns the default error message for `$attribute`.Tests
-----

[](#tests)

```
composer test
```

See [tests/](tests/) for the cases covered (happy path and errors) per rule.

AI assistant documentation
--------------------------

[](#ai-assistant-documentation)

See [AI\_USAGE.md](AI_USAGE.md).

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance93

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

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

Recently: every ~175 days

Total

8

Last Release

35d ago

Major Versions

v1.0.3 → 2.0.02026-07-09

PHP version history (2 changes)v1.0.0PHP ^8.2

v1.0.3PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/713da77764977a76a357f6b34361a7ab51bd55ea847b84112e3a38f5496af173?d=identicon)[hstanleycrow](/maintainers/hstanleycrow)

---

Top Contributors

[![hstanleycrow](https://avatars.githubusercontent.com/u/7930763?v=4)](https://github.com/hstanleycrow "hstanleycrow (12 commits)")

---

Tags

phpvalidatorvalidationrulesform validationFormsinput-validation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hstanleycrow-easyphpformvalidator/health.svg)

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

###  Alternatives

[bitapps/wp-validator

WordPress Validation and Sanitization Library

1310.4k3](/packages/bitapps-wp-validator)[iutrace/laravel-cuit-validator

Argentinian CUIT and CUIL Validator

1113.4k](/packages/iutrace-laravel-cuit-validator)

PHPackages © 2026

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