1

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);
});
Sasha
  • 764
  • 1
  • 13
  • 21

1 Answers1

3

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'.

Santiago Mendoza Ramirez
  • 1,497
  • 2
  • 13
  • 26