非常基本的问题,我正在尝试自定义 Laravel 中正则表达式验证规则的错误消息。特定规则适用于密码,要求密码包含 6-20 个字符,至少有一个数字以及一个大写和小写字母,因此我想将此信息传达给用户,而不仅仅是显示格式为“的默认消息”无效的”。
因此,我尝试通过几种不同的方式将消息添加到 lang 文件中:
1)
'custom' => array(
'password.regex:' => 'Password must contain at least one number and both uppercase and lowercase letters.'
)
2)
'custom' => array(
'password.regex' => 'Password must contain at least one number and both uppercase and lowercase letters.'
)
3)
'custom' => array(
'password.regex:((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20})' => 'Password must contain at least one number and both uppercase and lowercase letters.'
)
这些都不起作用。有没有办法做到这一点?
我能够通过使用这种方法来解决这个问题:
'custom' => array(
'password' => array(
'regex' => 'Password must contain at least one number and both uppercase and lowercase letters.'
)
)
但我很想知道为什么其他方法之一不起作用如果有人碰巧知道......?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)