Sasha
Sasha

Reputation: 764

Custom validation rules in Laravel 5

How can I add correctly custom validation rule in Laravel 5?

In Laravel 4 it was placed in some autoloaded file:

Validator::register('alpha_spaces', function($attribute, $value)
{
    return preg_match('/^([-a-z0-9_-\s])+$/i', $value);
});

Upvotes: 1

Views: 3498

Answers (1)

Santiago Mendoza Ramirez
Santiago Mendoza Ramirez

Reputation: 1657

You can check the documentation: http://laravel.com/docs/5.0/validation#custom-validation-rules

     Validator::extend('foo', function($attribute, $value, $parameters) {
         return $value == 'foo'; 
});

I think you only need to change 'register' with 'extend'.

Upvotes: 3

Related Questions