duanqianruan8448 2016-04-11 07:18
浏览 60
已采纳

Yii2 ActiveForm验证规则消息

I have some rules in the model:

[['username', 'email', 'password', 'password_repeat'],'required', 'message' => 'Can not be blank'],
['username', 'string', 'min' => 2, 'max' => 255],
['password', 'string', 'min' => 6, 'max' => 255],

I set the message for checking if any of these fields were blank. But how can I set messages to check inputs length.

I've tried:

['username', 'string', 'min' => 2, 'max' => 255, 'message' => 'too few characters'] Yet it doesn't seem to be correct.

  • 写回答

1条回答 默认 最新

  • dongyan1841 2016-04-11 07:37
    关注

    You need to set the tooShort property, http://www.yiiframework.com/doc-2.0/yii-validators-stringvalidator.html#$tooShort-detail

    ['username', 'string', 'min' => 2, 'max' => 255, 'tooShort' => 'too few characters']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部