Support the ongoing development of Laravel.io →
posted 10 years ago
Validation
Last updated 2 years ago.
0

validation.alpha_spaces is the output of a missing translation. The second piece of code in the tutorial you linked adds the custom validation error.

Add the following to your lang/en/validation.php file:

/*
|--------------------------------------------------------------------------
| Custom Validation Rules
|--------------------------------------------------------------------------
|
| Custom rules created in app/validators.php
|
*/
"alpha_spaces"     => "The :attribute may only contain letters and spaces.",

As for allowing numbers, add \d to the regular expression. So their first snippet would look like:

/*
* app/validators.php
*/

Validator::extend('alpha_spaces', function($attribute, $value)
{
    return preg_match('/^[\pL\s\d]+$/u', $value);
});

Bare in mind that \d will allow all digit characters, such as ٠١٢٣٤٥٦٧٨٩. Use 0-9 instead if you don't want that.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Dieter91 dieter91 Joined 9 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.