I followed this short tutorial: http://blog.elenakolevska.com/laravel-alpha-validator-that-allows-spaces/.
Now my question is, how can i add errors to it? Because now i just get this as an error:
validation.alpha_spaces
I'm also curious on how to add numbers to the validator? Thanks!
Edit:
If you don't want to open the link, this is basicly my code:
Validator::extend('alpha_spaces', function($attribute, $value) {
return preg_match('/^[\pL\s]+$/u', $value);
});
You need to pass a custom error message as well, for example:
Validator::extend('alpha_spaces', function($attribute, $value) {
// ...
});
Now prepare a message for this custom rule:
$messages = array('alpha_spaces' => 'Your custom error message for :attribute');
Use it like this (with $messages
):
$validator = Validator::make($input, $rules, $messages);
Here :attribute
will be replace with the form's field name.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments