【发布时间】:2013-12-17 16:19:23
【问题描述】:
非常基本的问题,我正在尝试为 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.'
)
这些都没有奏效。有没有办法做到这一点?
【问题讨论】:
标签: php validation laravel