Skip to content

RaoulvanWijk/Validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About my PHP Validator

How to install

composer require raoul/php-validator

Or

git clone https://github.com/RaoulvanWijk/Validator.git

How to use it?

To use my validator you can either instantiate the validator class

require_once __DIR__ .'/vendor/autoload.php';

use Raoul\Validator\Validator;

$validator = new Validator();

or create a new class that extends the base validator class

require_once __DIR__ .'/vendor/autoload.php';

use Raoul\Validator\Validator;

Class CustomValidator extends Validator
{
    public function rules()
    {
        return [
            // Your rules go here
        ];
    }

    public function messages()
    {
        return [
            // Your custom messages go here
        ];
    }
}

$validator = new CustomValidator();

And then call the validate method with the needed data

$validator->validate($data);

Specifying the rules

You have 2 options when specifying the rules when calling the validate method

$validator->validate($data, [
  'name' => ['required', 'min:4'],
  'email' => 'required|email'
  ]);

or in the rules() method

public function rules()
    {
        return [
            'name' => ['required', 'min:4'],
            'email' => 'required|email'
        ];
    }

Specifying custom validation messages

available validation rules

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages