duanqianruan8448 2016-04-11 15: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 15: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']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算