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

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

mirkorap/php-validator
======================

A PHP library to validate form fields.

626PHP

Since Jul 6Pushed 7y agoCompare

[ Source](https://github.com/mirkorap/PHP-Validator)[ Packagist](https://packagist.org/packages/mirkorap/php-validator)[ RSS](/packages/mirkorap-php-validator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP-Validator
=============

[](#php-validator)

This package provides tools to validate values.

Installation
============

[](#installation)

`composer require mirkorap/php-validator`

Constraint
==========

[](#constraint)

All values are validated with the usage of constraints. Below some examples of constraints that you can use:

BlankConstraint
---------------

[](#blankconstraint)

Validates that a value is blank.

NotBlankConstraint
------------------

[](#notblankconstraint)

Validates that a value is not blank.

NullConstraint
--------------

[](#nullconstraint)

Validates that a value is null.

NotNullConstraint
-----------------

[](#notnullconstraint)

Validates that a value is not null.

IsTrueConstraint
----------------

[](#istrueconstraint)

Validates that a value is true.

IsFalseConstraint
-----------------

[](#isfalseconstraint)

Validates that a value is false.

TypeConstraint
--------------

[](#typeconstraint)

Validates that a value is of a specific data type. You can choose among these types:

1. string
2. int
3. float
4. bool
5. array
6. object

EmailConstraint
---------------

[](#emailconstraint)

Validates that a value is a valid email address.

LengthConstraint
----------------

[](#lengthconstraint)

Validates that a given string length is between some minimum and maximum value.

UrlConstraint
-------------

[](#urlconstraint)

Validates that a given value is a valid url.

RegexConstraint
---------------

[](#regexconstraint)

Validates that a given value matches a regular expression.

IpConstraint
------------

[](#ipconstraint)

Validates that a given value is a valid ip.

RangeConstraint
---------------

[](#rangeconstraint)

Validates that a given number is between some minimum and maximum number.

EqualToConstraint
-----------------

[](#equaltoconstraint)

Validates that a given value is equal to another value.

NotEqualToConstraint
--------------------

[](#notequaltoconstraint)

Validates that a given value is not equal to another value.

IdenticalToConstraint
---------------------

[](#identicaltoconstraint)

Validates that a given value is identical to another value.

NotIdenticalToConstraint
------------------------

[](#notidenticaltoconstraint)

Validates that a given value is not identical to another value.

LessThanConstraint
------------------

[](#lessthanconstraint)

Validates that a given value is less than to another value.

LessThanOrEqualConstraint
-------------------------

[](#lessthanorequalconstraint)

Validates that a given value is less than or equal to another value.

GreaterThanConstraint
---------------------

[](#greaterthanconstraint)

Validates that a given value is greater than another value.

GreaterThanOrEqualConstraint
----------------------------

[](#greaterthanorequalconstraint)

Validates that a given value is grater than or equal to another value.

DateConstraint
--------------

[](#dateconstraint)

Validates that a given value is a valid date.

DatetimeConstraint
------------------

[](#datetimeconstraint)

Validates that a given value is a valid datetime.

ChoiceConstraint
----------------

[](#choiceconstraint)

This constraint is used to ensure that the given value is one of a given set of valid choices. To validate the value you should provide an array or a Closure. If you set a multiple to `true` the input value is expected to be an array instead of a single, scalar value. The constraint will check that each value of the input array can be found in the array of valid choices.

Create custom validation form
=============================

[](#create-custom-validation-form)

All of these constraints implement the interface Constraint. So if you want to create your custom constraint you should implement it.

To validate a form you should create your custom form class that extends the abstract base class `FormValidator`. This class accepts an array of `FieldValidator` to validate. So each field should be an instance of `FieldValidator` and should contains a set of constraints. Here a basic example:

```
class ContactFormValidator extends FormValidator
{

    private $companyName = null;
    private $firstName = null;
    private $lastName = null;
    private $email = null;
    private $phone = null;
    private $message = null;

    /**
     * @return FieldValidator|null
     */
    public function getCompanyName()
    {
        return $this->companyName;
    }

    /**
     * @param string $companyName
     */
    public function setCompanyName($companyName)
    {
        $constraints = array(
            new LengthConstraint(255),
        );

        $this->companyName = new FieldValidator('companyName', 'Company Name', $companyName, $constraints);
    }

    /**
     * @return FieldValidator|null
     */
    public function getFirstName()
    {
        return $this->firstName;
    }

    /**
     * @param string $firstName
     */
    public function setFirstName($firstName)
    {
        $constraints = array(
            new NotBlankConstraint(),
            new LengthConstraint(255),
        );

        $this->firstName = new FieldValidator('firstName', 'First name', $firstName, $constraints);
    }

    /**
     * @return FieldValidator|null
     */
    public function getLastName()
    {
        return $this->lastName;
    }

    /**
     * @param string $lastName
     */
    public function setLastName($lastName)
    {
        $constraints = array(
            new NotBlankConstraint(),
            new LengthConstraint(255),
        );

        $this->lastName = new FieldValidator('lastName', 'Last name', $lastName, $constraints);
    }

    /**
     * @return FieldValidator|null
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @param string $email
     */
    public function setEmail($email)
    {
        $constraints = array(
            new NotBlankConstraint(),
            new LengthConstraint(255),
        );

        $this->email = new FieldValidator('email', 'Email', $email, $constraints);
    }

    /**
     * @return FieldValidator|null
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * @param string $phone
     */
    public function setPhone($phone)
    {
        $constraints = array(
            new NotBlankConstraint(),
            new LengthConstraint(100),
        );

        $this->phone = new FieldValidator('phone', 'Phone', $phone, $constraints);
    }

    /**
     * @return FieldValidator|null
     */
    public function getMessage()
    {
        return $this->message;
    }

    /**
     * @param string $message
     */
    public function setMessage($message)
    {
        $constraints = array(
            new NotBlankConstraint(),
            new LengthConstraint(500),
        );

        $this->message = new FieldValidator('message', 'Message', $message, $constraints);
    }

    public function buildForm()
    {
        $fields = array(
            $this->getCompanyName(),
            $this->getFirstName(),
            $this->getLastName(),
            $this->getEmail(),
            $this->getPhone(),
            $this->getMessage(),
        );

        $this->setFields($fields);
    }

}

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4be007681cf5cf586007160b9c2dc62b05f49a24973300f2654789fba0ee23b0?d=identicon)[mirkorap](/maintainers/mirkorap)

---

Top Contributors

[![mirkorap](https://avatars.githubusercontent.com/u/33153699?v=4)](https://github.com/mirkorap "mirkorap (1 commits)")

---

Tags

form-validatorphp-validatorvalidation-rulesvalidator

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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