luckystar/validation

There is no license information available for the latest version (v2) of this package.

Validation library prepared for php.

v2 2024-04-13 21:27 UTC

This package is auto-updated.

Last update: 2024-10-14 01:06:03 UTC


README

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

Other Parameters

Error parameters

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

Step 1: Install Composer

composer require luckystar/validation

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

<?php
require_once 'vendor/autoload.php';

$validation = new LuckyStar\Validation\Validate;

// Add Rules

Step 3: Add Rules and Validate (example)

$rules = [
	'username' => [
		'rules' => 'max_length[3]|min_length[1]'
	],
	'password' => [
		'rules'  => 'max_length[10]|min_length[5]',
		'error_messages' => [
			'max_length' => 'Password is too long',
			'min_length' => 'Password is too short'
		]
	],
	'number' => [
		'rules' => 'is_numeric|max_length[8]|min_length[3]',
		'error_messages' => [
			'is_numeric' => ' Sayısal olmalı ...',
			'max_length' => 'Number is too long',
			'min_length' => 'Number is too short'
		]
	],
	'req' => [
		'rules' => 'required',
		'error_messages' => [
			'required' => 'This field is required'

		]
	]
];

$_POST = ['username' => '12345', 'password' => '12345', 'number' => '123sa45'];



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

if ($checker){
	//no errors
	foreach ($validation->getErrors() as $error){
		echo $error . "<br>";
	}
}else{
	echo "No errors";
}