PHPackages                             mousav1/validify - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. mousav1/validify

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

mousav1/validify
================

Validify is a powerful PHP validation library that provides flexible and customizable validation rules, error handling, and pre-validation callbacks.

v2.0.2(1y ago)210MITPHPPHP ^7.4 || ^8.0

Since Aug 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mousav1/validify)[ Packagist](https://packagist.org/packages/mousav1/validify)[ RSS](/packages/mousav1-validify/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (5)Used By (0)

Validify
========

[](#validify)

Table of Contents
-----------------

[](#table-of-contents)

- [Validify](#validify)
    - [Table of Contents](#table-of-contents)
    - [Introduction](#introduction)
    - [Features](#features)
    - [Installation](#installation)
    - [Quick Start](#quick-start)
        - [Basic Validation](#basic-validation)
        - [Fluent Validation](#fluent-validation)
    - [Advanced Usage](#advanced-usage)
        - [Custom Validation Rules](#custom-validation-rules)
        - [Conditional Validation](#conditional-validation)
        - [Date and Time Validation](#date-and-time-validation)
            - [Date Format](#date-format)
            - [After and Before Rules](#after-and-before-rules)
        - [Custom Error Messages](#custom-error-messages)
        - [Field Aliases](#field-aliases)
        - [Pre-Validation Callbacks](#pre-validation-callbacks)
    - [Available Rules](#available-rules)
    - [Contributing](#contributing)
        - [Steps to Contribute:](#steps-to-contribute)
    - [License](#license)

Introduction
------------

[](#introduction)

**Validify** is a lightweight and extensible PHP validation library that simplifies validating user inputs. Whether you're building an API, a form, or any application requiring data validation, Validify provides a powerful and intuitive way to handle it.

Features
--------

[](#features)

- **Simple API**: Easy-to-use API for defining and executing validation rules.
- **Extensible**: Define custom validation rules to fit specific use cases.
- **Pre-Validation Callbacks**: Execute custom logic before validation.
- **Conditional Validation**: Dynamically apply rules based on conditions.
- **Nested Data Support**: Validate complex data structures using dot notation.
- **Comprehensive Built-in Rules**: Includes a wide range of predefined validation rules.

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

[](#installation)

To install the package, use Composer:

```
composer require mousav1/validify
```

Quick Start
-----------

[](#quick-start)

### Basic Validation

[](#basic-validation)

Here is an example of simple validation using Validify:

```
use Mousav1\Validify\Validator;

$data = [
    'username' => 'john_doe',
    'email' => 'john@example.com',
    'age' => 25,
];

$validator = new Validator($data, [
    'username' => ['required', 'alpha'],
    'email' => ['required', 'email'],
    'age' => ['required', 'numeric', 'min:18'],
]);

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

### Fluent Validation

[](#fluent-validation)

Define validation rules using a fluent interface for better readability:

```
use Mousav1\Validify\Validator;

$data = [
    'name' => 'prefix_name',
];

$validator = new Validator($data);

$validator->field('name')
    ->required()
    ->applyRules();

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

Advanced Usage
--------------

[](#advanced-usage)

### Custom Validation Rules

[](#custom-validation-rules)

Extend Validify with your own custom rules:

```
use Mousav1\Validify\Validator;

Validator::extend('even', function () {
    return new class extends \Mousav1\Validify\Rules\Rule {
        public function passes($field, $value, array $data): bool
        {
            return $value % 2 === 0;
        }
        public function name(): string
        {
            return 'even';
        }
        public function message($field): string
        {
            return "{$field} must be an even number.";
        }
    };
});

$data = ['number' => 3];

$validator = new Validator($data, [
    'number' => ['even']
]);

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

### Conditional Validation

[](#conditional-validation)

Apply rules dynamically based on conditions:

```
$data = [
    'age' => 20,
    'license' => ''
];

$validator = new Validator($data);

$validator->addConditionalRule('license', ['required'], function ($data) {
    return $data['age'] > 18;
});

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

### Date and Time Validation

[](#date-and-time-validation)

Validate date and time fields using predefined rules:

#### Date Format

[](#date-format)

```
$data = [
    'birthdate' => '2024-09-01',
];

$validator = new Validator($data, [
    'birthdate' => ['required', 'date_format:Y-m-d'],
]);

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

#### After and Before Rules

[](#after-and-before-rules)

```
$data = [
    'start_date' => '2024-01-01',
    'end_date' => '2024-02-01',
];

$validator = new Validator($data, [
    'end_date' => ['required', 'date_format:Y-m-d', 'after:start_date'],
]);

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

### Custom Error Messages

[](#custom-error-messages)

Define custom error messages for specific rules:

```
use Mousav1\Validify\Validator;

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

$validator = new Validator($data, [
    'username' => ['required'],
    'email' => ['required', 'email'],
]);

$validator->setCustomMessages([
    'username.required' => 'The username field cannot be empty.',
    'email.email' => 'Please provide a valid email address.',
]);

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

### Field Aliases

[](#field-aliases)

Use aliases for more readable error messages:

```
$validator->setAliases([
    'email' => 'Email Address'
]);

$validator->validate();

print_r($validator->getErrors());
```

### Pre-Validation Callbacks

[](#pre-validation-callbacks)

Execute logic before validation starts:

```
$validator->beforeValidate(function (&$data) {
    $data['username'] = strtolower($data['username']);
});
```

Available Rules
---------------

[](#available-rules)

- **required**
- **email**
- **min**
- **max**
- **numeric**
- **confirmed**
- **url**
- **in**
- **between**
- **regex**
- **alpha**
- **optional**
- **required\_with**
- **array**
- **integer**
- **boolean**
- **not\_in**
- **uppercase**
- **lowercase**
- **json**
- **date\_format**
- **after**
- **before**

Contributing
------------

[](#contributing)

Contributions are welcome! Feel free to submit a pull request or open an issue.

### Steps to Contribute:

[](#steps-to-contribute)

1. Fork the repository.
2. Create a new branch for your feature/bugfix.
3. Write clear and descriptive commit messages.
4. Submit a pull request with detailed explanation.

License
-------

[](#license)

This package is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance42

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

4

Last Release

475d ago

Major Versions

v1.0.0 → v2.0.02025-01-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe615a80c0e34ddb2b63c010eb7b8c0b6edfdc3fbd3952d0bcdc33c9b399e747?d=identicon)[mousav1](/maintainers/mousav1)

---

Top Contributors

[![mousav1](https://avatars.githubusercontent.com/u/108792130?v=4)](https://github.com/mousav1 "mousav1 (26 commits)")

---

Tags

error-handlingform-validationphpvalidatevalidationvalidatorphpvalidationruleserror handlingdata validationcustom validationpre-validation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mousav1-validify/health.svg)

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

###  Alternatives

[blakvghost/php-validator

PHPValidator is a modern PHP library for data validation in your PHP applications. It provides a flexible and extensible way to validate data using predefined rules or by creating custom validation rules.

2524.2k2](/packages/blakvghost-php-validator)[h4cc/phpqatools

A meta composer package for PHP QA Tools.

6418.6k1](/packages/h4cc-phpqatools)[marwanalsoltany/mighty

The last validation library you will ever need!

591.3k](/packages/marwanalsoltany-mighty)[thehocinesaad/laravel-error-ai

This package adds Ask AI button to the error page.

2214.4k](/packages/thehocinesaad-laravel-error-ai)

PHPackages © 2026

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