Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

guillaumebriday/laravel-blog

1797 stars
2 code files
View guillaumebriday/laravel-blog on GitHub

app/Rules/AlphaName.php

Open in GitHub
use Illuminate\Contracts\Validation\Rule;
 
class AlphaName implements Rule
{
public function passes($attribute, $value)
{
if (! is_string($value) && ! is_numeric($value)) {
return false;
}
 
return preg_match('/^(?:[\pL\pN\pM]+[\pZ\'_-])*[\pL\pN\pM]+$/u', $value) > 0;
}
 
public function message(): string
{
return trans('validation.alpha_name');
}
}

app/Http/Requests/UsersRequest.php

Open in GitHub
use App\Rules\AlphaName;
use Illuminate\Foundation\Http\FormRequest;
 
class UsersRequest extends FormRequest
{
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255', new AlphaName],
'email' => 'required|email|unique:users,email,' . auth()->user()->id,
];
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.