Reputation: 1755
I am trying to add a validation rule to only accept letters. I am using the regex
rule but its still not working. Here is my code below:
/**
* Validate request/input
**/
$this->validate($request, [
'name' => 'required|regex:/^[\pL\s\-]+$/u|max:255|unique:users,name,'.$user->id,
'email' => 'required|email|max:255|unique:users,email,'.$user->id,
]);
Whenever I enter a name like Foo Foo
, it is still succesful in signing up.
Any idea what I am doing wrongly?
Upvotes: 20
Views: 85621
Reputation: 9627
According to laravel documentation you can use :
alpha
for entirely alphabetic characters alpha_dash
for alpha-numeric characters, as well as dashes and underscores and finally alpha_num
for entirely alpha-numeric characters.Upvotes: 42