codesvault/validator

Data validation library

1.1.2 2023-07-26 12:44 UTC

This package is auto-updated.

Last update: 2024-10-26 15:16:58 UTC


README

Data validation composer package.

Installation

Install using composer.

composer require codesvault/validator


Usage

$validator = Validator::validate(
    [
		'username'	=> 'required|stringOnly',
		'full_name'	=> 'stringWithSpace',
		'password'	=> 'required|min:8',
		'email'		=> 'required|email',
    ],
);

It'll get data from $_REQUEST by default. But you also can pass data as second parameter.

$validator = Validator::validate(
	[
		'username'	=> 'required|stringOnly',
		'full_name'	=> 'stringWithSpace'
	],
	[
		'username'	=> 'abmsourav',
		'full_name'	=> 'Keramot UL Islam'
	]
);


Handling Errors

If any data is invalid then error method will return error messages array. Otherwise it'll return false.
getData method will return validated data array.

$error = $validator->error();
if ($error) {
	return $error;
}
$validator->getData();


Available Rules