laravel仅字母验证规则 [英] laravel validation rule for only letters
本文介绍了laravel仅字母验证规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试添加验证规则以仅接受字母.我正在使用 regex
规则,但是它仍然无法正常工作.这是我的代码如下:
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,
]);
每当我输入 Foo Foo
之类的名称时,它仍然可以成功注册.
Whenever I enter a name like Foo Foo
, it is still succesful in signing up.
知道我在做什么错吗?
推荐答案
我认为您的正则表达式失败,我在 Regexr 并且无法使其正常运行,请尝试以下操作:
Your regex fails I think, I tried it on Regexr and couldn't get it to function, try this:
'name' => 'required|regex:/^[a-zA-Z]+$/u|max:255|unique:users,name,'.$user->id,
让我知道你过得怎么样.
Let me know how you get on.
这里仅是正则表达式:^ [a-zA-Z] + $
Here's the regex only: ^[a-zA-Z]+$
这篇关于laravel仅字母验证规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文