PHPackages                             rizwan3d/validation-my-php - 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. rizwan3d/validation-my-php

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

rizwan3d/validation-my-php
==========================

PHP validation library

0.0.5(1y ago)41311MITPHPPHP &gt;=7.1

Since Sep 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rizwan3d/ValidationMyPhp)[ Packagist](https://packagist.org/packages/rizwan3d/validation-my-php)[ Fund](https://www.buymeacoffee.com/rizwan3d)[ Fund](https://www.paypal.com/paypalme/rizwan3d)[ RSS](/packages/rizwan3d-validation-my-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)DependenciesVersions (11)Used By (0)

ValidationMyPhp
===============

[](#validationmyphp)

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

[](#introduction)

The `Validation` class is a PHP utility for performing data validation and error handling. It is designed to validate user-provided data against a set of rules and return error messages when validation fails.

Usage
-----

[](#usage)

### Installation

[](#installation)

#### Composer

[](#composer)

You can easily install the `Validation` class and its dependencies using Composer. If you haven't already installed Composer globally, you can do so by following the instructions on the [Composer website](https://getcomposer.org/download/).

Once Composer is installed, you can add the `validation-my-php` package to your project by running the following command in your project's root directory:

```
composer require rizwan3d/validation-my-php
```

### Initialization

[](#initialization)

To use the `Validation` class, you first need to initialize it and set up your database connection parameters if needed. Here's an example of how to do it:

```
use ValidationMyPhp\Validation;

Validation::$DB_HOST = '127.0.0.1';
Validation::$DB_NAME = 'database';
Validation::$DB_PASSWORD = '';
Validation::$DB_USER = 'root';

$validation = new Validation();
```

### Data Validation

[](#data-validation)

Once the `Validation` object is created, you can validate data using the `validate` method. You need to provide the data to validate, validation rules, and optional custom error messages. Here's an example of how to validate data:

```
$data = [
    'firstname' => '',
    'username' => '33158413',
    'address' => 'This is my address',
    'zipcode' => '1',
    'email' => 'jo@',
    'password' => 'test123',
    'password2' => 'test',
];

$fields = [
    'firstname' => 'required | max:255',
    'lastname' => 'required| max: 255', // Note: 'lastname' field is missing in the data
    'address' => 'required | min: 10, max:255',
    'zipcode' => 'between: 5,6',
    'username' => 'required | alphanumeric | between: 3,255 | unique: users,username',
    'password' => 'required | secure',
    'password2' => 'required | same:password'
];

$errors = $validation->validate($data, $fields, [
    'required' => 'The %s is required',
    'password2' => ['same'=> 'Please enter the same password again']
]);

print_r($errors);
```

In the example above, the `validate` method will return an array of error messages for fields that failed validation.

### Validation Rules

[](#validation-rules)

You can specify various validation rules for each field in the `fields` array. Here are some common validation rules:

- `required`: The field must not be empty.
- `max:X`: The field's length must not exceed X characters.
- `min:X`: The field's length must be at least X characters.
- `between:X,Y`: The field's length must be between X and Y characters.
- `alphanumeric`: The field must contain only alphanumeric characters.
- `numeric`: The field must contain only numeric characters.d
- `unique:table,column`: Check if the field value is unique in the specified database table and column.
- `unique:table,column,soft_delete_col`: Check if the field value is unique in the specified database table and column.
- `exist:table,column`: Check if the field value is exist in the specified database table and column.
- `exist:table,column,soft_delete_col`: Check if the field value is exist in the specified database table and column.
- `email`: Validate if the field is a valid email address.
- `secure`: Validate if the field contains a secure password (custom rule).
- `same:field_name`: Validate if the field is the same as another field (e.g., password confirmation).
- `date:format`: Validate if the field is the date in provided formate.
- `url`: Validate if the field is the valid URL.
- `url:formate`: Validate if the field is the valid URL in provided formate (such as http,https,ftp,custom,mailto,jdbc). Multiple formatcan be passed by saprting with ','.
- `accepted`: Validate if the field has yes, on, 1 and true value.
- `after:time`: Validate if the field has date after provided time.
- `alpha`: Validate if the field must contain only alphabetic characters.
- `extension`: Validates if the given File Extension is Valid.

### Custom Error Messages

[](#custom-error-messages)

You can provide custom error messages for each validation rule. In the example, custom error messages are defined in the third argument of the `validate` method. You can use `%s` as a placeholder for the field name in error messages.

Conclusion
----------

[](#conclusion)

The `Validation` class simplifies the process of validating user input data in PHP applications. It allows you to define validation rules, apply them to data, and retrieve error messages for fields that fail validation. This helps improve the security and reliability of your application by ensuring that user input meets your criteria.

Support:
--------

[](#support)

[ ![rizwan3d](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/rizwan3d)

[![PayPal](https://camo.githubusercontent.com/b811c9741e973ac713b2a33c9bfd025f0fad57a7b1d57a29d03b30badb6d04f9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50617950616c2d3030343537433f7374796c653d666f722d7468652d6261646765266c6f676f3d70617970616c266c6f676f436f6c6f723d7768697465)](https://paypal.me/rizwan3d)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 94.1% 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 ~46 days

Recently: every ~70 days

Total

7

Last Release

681d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d630ddea99c446cc703e55735235ef51c11b7424b30f758f316a548343ac714?d=identicon)[rizwan3d](/maintainers/rizwan3d)

---

Top Contributors

[![rizwan3d](https://avatars.githubusercontent.com/u/10514337?v=4)](https://github.com/rizwan3d "rizwan3d (64 commits)")[![musman2002](https://avatars.githubusercontent.com/u/87014565?v=4)](https://github.com/musman2002 "musman2002 (3 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

phpphp-frameworkphp-libraryphp-validationphp7php8

### Embed Badge

![Health badge](/badges/rizwan3d-validation-my-php/health.svg)

```
[![Health](https://phpackages.com/badges/rizwan3d-validation-my-php/health.svg)](https://phpackages.com/packages/rizwan3d-validation-my-php)
```

###  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)
