PHPackages                             luckystar/validation - 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. luckystar/validation

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

luckystar/validation
====================

Validation library prepared for php.

v2(2y ago)012PHP

Since Apr 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/HasanKaya53/php-validation-library)[ Packagist](https://packagist.org/packages/luckystar/validation)[ RSS](/packages/luckystar-validation/feed)WikiDiscussions main Synced today

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

Validation library
===================

[](#validation-library-)

This is a lightweight PHP validation library designed to simplify the process of validating input data in web applications. It provides a set of commonly used validation rules such as required fields, maximum and minimum lengths, numeric checks, and more. With easy integration and customizable error messages, it streamlines the validation process, ensuring data integrity and user-friendly error handling.

###  Rules List

[](#-rules-list-)

 Rule Description Example  required This field is required required max\_length This field must be less than {max\_length} characters long max\_length\[10\] min\_length This field must be at least {min\_length} characters long min\_length\[5\] is\_numeric This field must contain only numbers is\_numeric valid\_email  This field must contain a valid email address valid\_email valid\_url  This field must contain a valid URL valid\_url valid\_ip  This field must contain a valid IP address valid\_ipmin This field must be greater than or equal to {min} min\[5\]max This field must be less than or equal to {max} max\[10\] date This field must be a valid date date###  Other Parameters

[](#-other-parameters-)

 Parameter Type Description Example  error\_messages Array Custom error messages error\_messages =&gt; \['required' =&gt; 'This field is required'\]###  Error parameters

[](#-error-parameters-)

 Parameter Description Example  :field Field name 'error\_messages' =&gt; \[ 'required' =&gt; ':field is required', 'max\_length' =&gt; ':field is too long', 'min\_length' =&gt; ':field is too short' \] :number  Field Number  'error\_messages' =&gt; \[ 'min' =&gt; ':field must be greater than or equal to :number', 'max' =&gt; ':field must be less than or equal to :number' \]### set rules...

[](#set-rules)

```
$rules = [
    'username' => 'rules'...
];

//or ..

$rules = [
    'username' => [
        'rules' => 'required|max_length[10]|min_length[5]',
        'error_messages' => [
            'required' => ':field is required',
            'max_length' => 'Username is too long max: :number',
            'min_length' => 'Username is too short min:  :number'
        ]
    ]
];

$checker = $validation->validateRule($_POST, $rules);
```

###  How to install and run the project

[](#-how-to-install-and-run-the-project-)

### Step 1: Install Composer

[](#step-1-install-composer)

```
composer require luckystar/validation
```

### Step 2: First, require the composer autoloader in your script

[](#step-2-first-require-the-composer-autoloader-in-your-script)

```
