codesvault / validator
Data validation library
1.1.2
2023-07-26 12:44 UTC
Requires
- php: >=7.1
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();