PHPackages                             hasan-22/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. hasan-22/form-validator

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

hasan-22/form-validator
=======================

Form data validation

v1.0.0(3y ago)010MITPHPPHP &gt;=7.4

Since Feb 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/HASSAN-22/form-validator)[ Packagist](https://packagist.org/packages/hasan-22/form-validator)[ Docs](https://github.com/HASSAN-22/form-validator)[ RSS](/packages/hasan-22-form-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

### Form data validator

[](#form-data-validator)

### install

[](#install)

```
composer require hasan-22/form-validator
```

---

usage
-----

[](#usage)

```
require_once __DIR__ . '/vendor/autoload.php';

$data = ['name'=>'armia','age'=>''];
$result = \Validation\Validator::validate(
    [
        'name'=>[
            'rules'=>['Required','Max:20'],
        ],
        'age'=>[
            'rules'=>['Required', 'Numeric'],
        ]
    ],$data);

print_r($result);

// Output:
// [
//     [0] => [
//         [age] => The field `age` is required
//     ],
//     [1] => [
//         [age] => The field `age` must be numeric
//     ]
// ]

// If all validation passes, you get an empty array
```

---

### with custom message

[](#with-custom-message)

```
require_once __DIR__ . '/vendor/autoload.php';

$data = ['name'=>'armia','age'=>''];
$result = \Validation\Validator::validate(
    [
        'name'=>[
            'rules'=>['Required','Max:20'],
            'messages'=>['custom required msg']
        ],
        'age'=>[
            'rules'=>['Required', 'Numeric'],
            'messages'=>['custom required msg','custom numeric msg']
        ]
    ],$data);

// Output:
// [
//     [0] => [
//         [age] => custom required msg
//     ],
//     [1] => [
//         [age] => custom numeric msg
//     ]
// ]

// If all validation passes, you get an empty array

```

---

### If you want to add custom validation, do so

[](#if-you-want-to-add-custom-validation-do-so)

```
    class Email implements \Validation\ValidationInterface{

        private array $formData;

        private array $errorMessage;

        private string $field;

        private string $additional;

        public function validate(){
            if(!filter_var($this->formData[$this->field], FILTER_VALIDATE_EMAIL)){
                return $this->errorMessage;
            }
        }

         public function formData(array $formData){
            $this->formData = $formData;
        }

        public function message(string $errorMessage){
            $this->errorMessage = [$this->field => empty($errorMessage) ? "The `{$this->field}` field is not an email" : $errorMessage];
        }

        public function field(string $field){
            $this->field = $field;
        }

        public function additionalData(string $additional)
        {
            $this->additional = $additional;
        }
    }

```

---

#### Now you can use the Email class like this

[](#now-you-can-use-the-email-class-like-this)

```
require_once __DIR__ . '/vendor/autoload.php';
require_once 'Email.php';

$formData = ['email'=>'armia@gmail.com'];
$result = \Validation\Validator::validate(
    [
        'email'=>[
            'rules'=>['Required','Email']
        ],
    ],$data);

//Output:
//[]
//If all validation passes, you get an empty array
```

---

### Regex:pattern

[](#regexpattern)

The field under validation must match the given regular expression.

```
$data = ['password'=>'123456','age'=>''];
$result = \Validation\Validator::validate(
    [
        'password'=>[
            'rules'=>['Regex:/[1-6]/']
        ]
    ],$data);
```

---

### Available validations

[](#available-validations)

ValidtionDescriptionExampleRequiredChecks that the field is not empty, these items are considered empty \[ '', 0, null \]BetweenChecks if the field is between two valuesBetween:4,10EmailChecks if the field is emailInChecks if the field has a series of values or notIn:admin,customer,vendorMaxChecks the field must be less than or equal to a valueMax:20MinChecks that the field must be greater than or equal to a valueMin:7NumericChecks that the field must be a numberStrChecks that the field must be a stringRegexThe field under validation must match the given regular expressionRegex:/pattern/

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

1200d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/af6d6cd4238d0a9280e4caaabff0c1280f8540ac344cb485ded6468486a28070?d=identicon)[HASSAN-22](/maintainers/HASSAN-22)

---

Top Contributors

[![HASSAN-22](https://avatars.githubusercontent.com/u/63023595?v=4)](https://github.com/HASSAN-22 "HASSAN-22 (12 commits)")

---

Tags

laravelvalidationform validationhasan

### Embed Badge

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

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

###  Alternatives

[stuyam/laravel-phone-validator

A phone validator for Laravel using the free Twilio phone lookup service.

2861.3k](/packages/stuyam-laravel-phone-validator)[skysplit/laravel5-intl-translation

Laravel 5 package for better translation syntax using php-intl extension

10106.2k](/packages/skysplit-laravel5-intl-translation)[pacerit/laravel-polish-validation-rules

Simple Polish Validation rules for Laravel and Lumen framework

1449.9k](/packages/pacerit-laravel-polish-validation-rules)[laravel-validation-rules/ip

Validate if an ip address is public or private.

1629.7k](/packages/laravel-validation-rules-ip)[cohensive/validation

Extra functionality for Laravel 5 Validator.

1513.9k](/packages/cohensive-validation)[fab2s/dt0

Immutable DTOs with bidirectional casting. No framework required. 8x faster than the alternative.

101.6k1](/packages/fab2s-dt0)

PHPackages © 2026

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