PHPackages                             pnhs/form\_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. pnhs/form\_validator

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

pnhs/form\_validator
====================

Validates forms and other strings

v1.0.09(1mo ago)0961MITPHP

Since Jun 6Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/seraf-im/formValidator)[ Packagist](https://packagist.org/packages/pnhs/form_validator)[ Docs](http://github.com/seraf-im/form-validator)[ RSS](/packages/pnhs-form-validator/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (2)Versions (11)Used By (0)

Form Validator [![Build Status](https://camo.githubusercontent.com/5b64dda46816fcb82266f5df09a94e901a194a2de9e53032efe1d53f5809a0ac/68747470733a2f2f7472617669732d63692e636f6d2f73657261662d696d2f666f726d56616c696461746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/seraf-im/formValidator)
================================================================================================================================================================================================================================================================================================================

[](#form-validator-)

  English  | [ Portuguese ](https://github.com/seraf-im/formValidator/tree/master/lang/portuguese#readme)

Form Validator is an open source library for validating data received from users by forms or other means. The focus is to be simple and have an architecture compatible with the latest features of PHP.

We provide an example using "Form URL Encoded" (submission via simple HTML form) and a JSON example (submission via VUE-JS), we suggest you test both examples by doing **Installation for testing**, logo bellow

Help the Project to continue, donate a coffee!
----------------------------------------------

[](#help-the-project-to-continue-donate-a-coffee)

[![Pague com PagSeguro - é rápido, grátis e seguro!](https://camo.githubusercontent.com/946696bf62833f81eb9ccd9739860d21994df3ce02641259d4f4930ea5b0b9dd/68747470733a2f2f7374632e70616773656775726f2e756f6c2e636f6d2e62722f7075626c69632f696d672f626f746f65732f646f61636f65732f3230397834382d646f61722d617373696e612e676966)](https://pag.ae/7VUx6v4sL)or pix for brazilians:

Installation for testing
------------------------

[](#installation-for-testing)

To test before including it in your project, open the terminal, prompt or powershell and run the commands below:

```
git clone https://github.com/seraf-im/formValidator.git
cd formValidator
composer install --no-dev
cd samples
php -S localhost:8000

```

Remembering that it is necessary that you have previously installed PHP and GIT.

Installation in your project
----------------------------

[](#installation-in-your-project)

### Composer

[](#composer)

If you already know **Composer** (which is highly recommended), simply open the terminal, prompt or powershell in your project folder and type:

```
composer require pnhs/form_validator

```

How to use
----------

[](#how-to-use)

That's the best part. It couldn't be simpler, see a basic example:

```
use Pnhs\FormValidator\Validator;

$form = [
    "username" => "nicolahsss",
    "password" => "password26"
];

$validator = new Validator($form);

/*
 * required: Is required
 * no_empty: Cannot be sent blank
 * min_len: Minimum number of characters
 * max_len: Maximum number of characters
 */
$username = $validator->rules('username', 'required|no_empty|min_len:3|max_len:10');
$password = $validator->rules('password', 'required|no_empty|min_len:8');

//If there are errors, it returns json with the errors, if everything is fine, it returns NULL
$errors = $validator->errors();

//See the result
var_dump($username, $password, $errors ?? "OK");
```

**Yes, just that!** Just use the rules according to your need, if you wish you can contribute to the project by adding new rules. In the **samples** folder there are examples of using all the rules.

Supported Rules
---------------

[](#supported-rules)

Currently the Form Validator works with the following rules, remember you can always add more:

  Rule Information Details   **array**     **date** Y-m-d standard date format If your date has another pattern for example d/m/Y, just use this way **"date:d/m/Y"**. The return always follows the Y-m-d pattern   **datetime** Y-m-d H:i:s standard date format If your date has another pattern for example d/m/Y H:i:s, just use this way **"date:d/m/Y H:i:s"**. The return always follows the pattern Y-m-d H:i:s   **decimal** 2 standard decimal places If you want to use a number of decimal places other than 2, use  **"decimal: x"** , changing  **x**  to the desired number of decimal places.   **email**     **exact:x**  To define the number of characters, change the **x** to the desired amount   **integer**     **max\_len:x**     **min\_len:x**      For  **min\_len**  and  **max\_len** , change  **x**  to the desired number of characters    **no\_empty**     **numeric**     **required**  It can be empty, if you want the field to be required and not empty use both rules   **string**   Custom error code
=================

[](#custom-error-code)

You can use the # (hash) after the rule to enter the custom error code if you wish.

```
$validator->rules('username', 'required#2012|min:3#9999|max:10');
//In this example, if the value was not entered, the custom error code "2012" will be returned, if the number of characters is less than 3, the custom error "9999" will be returned.

```

Future rules
------------

[](#future-rules)

- username
- Password policy
- Document Validation\*
- Phone validation\*

\*We are looking for the best way to include these rules as they change by document type, state and country. Contribution
------------

[](#contribution)

Every contribution is welcome. If you want to add new rules, feel free to explore the code, see how simple it is to integrate any rule into the library.

Translation
-----------

[](#translation)

Also collaborate by including and correcting translations.

License
-------

[](#license)

- MIT License

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance89

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Recently: every ~252 days

Total

10

Last Release

56d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12789282?v=4)[Nicola Serafim](/maintainers/nicolahsss)[@nicolahsss](https://github.com/nicolahsss)

---

Top Contributors

[![nicolahsss](https://avatars.githubusercontent.com/u/12789282?v=4)](https://github.com/nicolahsss "nicolahsss (56 commits)")

---

Tags

validatorvalidationformform validatorformulary

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[barbieswimcrew/zip-code-validator

Constraint class for international zipcode validation

772.3M](/packages/barbieswimcrew-zip-code-validator)[phpexperts/datatype-validator

An easy to use data type validator (both strict and fuzzy).

141.1M2](/packages/phpexperts-datatype-validator)

PHPackages © 2026

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