PHPackages                             rohit-sagar/validatorplus - 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. rohit-sagar/validatorplus

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

rohit-sagar/validatorplus
=========================

A simple light-weight php validator package

0.0.0(1y ago)00[1 issues](https://github.com/rohit-sagar256/validatorPlus/issues)MITPHPPHP &gt;=8.2CI passing

Since May 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rohit-sagar256/validatorPlus)[ Packagist](https://packagist.org/packages/rohit-sagar/validatorplus)[ RSS](/packages/rohit-sagar-validatorplus/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

[![Run Tests](https://github.com/rohit-sagar256/validatorPlus/actions/workflows/run-tests.yml/badge.svg)](https://github.com/rohit-sagar256/validatorPlus/actions/workflows/run-tests.yml)

ValidatorPlus
=============

[](#validatorplus)

**ValidatorPlus** is a lightweight, chainable validation package built in PHP — perfect for console applications, CLI tools, or any PHP project where you want custom and clean validation without relying on full-stack frameworks.

This package was created while learning **Composer**, **design patterns**, and **package publishing** — and has been structured to be **extensible**, **testable**, and **easy to use**.

---

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

[](#installation)

```
composer require rohit-sagar/validatorplus
```

---

Why Use ValidatorPlus?
----------------------

[](#why-use-validatorplus)

- Built using real design patterns (Chain of Responsibility, Strategy)
- Fully chainable syntax for rules
- Supports label (alias) for human-friendly error messages
- Fully tested using PHPUnit
- Easily extendable — add your own rules in seconds
- Designed for clarity and learning — perfect for devs who want to understand how validation works under the hood

---

Quick Example
-------------

[](#quick-example)

```
use ValidatorPlus\Validator;

$data = [
    'name' => '',
    'email' => 'invalid-email'
];

$validator = new Validator();

$validator->field('name')
    ->label('Full Name')   // Optional alias
    ->required()
    ->min(3);

$validator->field('email')
    ->required()
    ->email();

if (!$validator->validate($data)) {
    print_r($validator->errors());
}
```

### Output

[](#output)

```
[
    'name' => ['The Full Name field is required.'],
    'email' => ['The email must be a valid email address.']
]
```

---

Available Rules (So far)
------------------------

[](#available-rules-so-far)

RuleDescriptionrequiredField must be present and not emptymin:xMinimum string lengthmax:xMaximum string lengthemailMust be a valid email addressYou can chain as many rules as you like on any field.

---

Add Your Own Rule
-----------------

[](#add-your-own-rule)

You can define custom rules using the provided `RuleInterface`.

```
use ValidatorPlus\Contracts\RuleInterface;

class StartsWithA implements RuleInterface
{
    protected string $label = '';

    public function passes(string $field, $value): bool {
        return is_string($value) && str_starts_with($value, 'A');
    }

    public function message(string $field): string {
        return "The {$this->label} must start with the letter A.";
    }

    public function setLabel(string $label): void {
        $this->label = $label;
    }
}
```

### Use it in validation

[](#use-it-in-validation)

```
$validator->field('nickname')
    ->label('Nickname')
    ->addRule(new StartsWithA());
```

This approach allows you to add as many custom rules as you want no need to modify the core.

---

Aliases / Labels
----------------

[](#aliases--labels)

Use `.label()` to define a human-readable name for a field, which is reflected in error messages:

```
$validator->field('email')->label('Email Address')->required();
```

Error will say `The Email Address field is required.`

---

Testing
-------

[](#testing)

This package includes tests using PHPUnit.

```
vendor/bin/phpunit
```

You can add more tests to the `tests/` folder to ensure coverage of all your custom rules and logic.

---

**Structure:**

```
src/
├── Validator.php           // Main entry point
├── FieldValidator.php      // Handles rule chains for a field
├── Contracts/
│   └── RuleInterface.php   // Interface for all rules
├── Rules/
│   ├── RequiredRule.php
│   ├── MinRule.php
│   ├── MaxRule.php
│   └── EmailRule.php
tests/
composer.json

```

---

Notes
-----

[](#notes)

This library was built as a learning project and is designed to be easy to read and extend. You are encouraged to:

- Create and share your own rules
- Fork and improve it further
- Use it in CLI tools or simple web backends

If you’re learning design patterns, open the source and explore how each part connects. The code is your teacher.

---

License
-------

[](#license)

MIT — use it freely in personal or commercial projects.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance50

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

365d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e1245e675c9d46a0dc8ab739b97035523f15d8a5baee4eb474c09469071ea7ba?d=identicon)[rohit-sagar256](/maintainers/rohit-sagar256)

---

Top Contributors

[![rohit-sagar256](https://avatars.githubusercontent.com/u/70800042?v=4)](https://github.com/rohit-sagar256 "rohit-sagar256 (12 commits)")

---

Tags

beginnerphpsimple-projectvalidator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rohit-sagar-validatorplus/health.svg)

```
[![Health](https://phpackages.com/badges/rohit-sagar-validatorplus/health.svg)](https://phpackages.com/packages/rohit-sagar-validatorplus)
```

###  Alternatives

[eniams/safe-migrations

Warn you when a migration is unsafe

56237.5k](/packages/eniams-safe-migrations)

PHPackages © 2026

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