相当基本的问题,我正在尝试为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.'
)
)
但我想知道如果有人碰巧知道其他方法为何不起作用...?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句