【问题标题】:Laravel Validation = integer value must > 2 if checkbox is checkedLaravel 验证 = 如果选中复选框,则整数值必须 > 2
【发布时间】:2017-11-02 06:03:19
【问题描述】:

如果选中复选框,如何验证必须大于 2textbox 的值。

<input type='checkbox' name='chk'>
<input type='text' name='txt'>

【问题讨论】:

    标签: laravel


    【解决方案1】:

    这似乎对我有用:

    'txt' => 'required_if:chk,1|integer|between:2,99
    

    【讨论】:

      【解决方案2】:

      在 laravel 验证规则中,您必须检查 checkbox 是否为 checked。如果它是checked,那么你必须验证textbox

      $rules = ['txt'=>'min:2']
      

      参考这个链接 Laravel: validate a integer field that needs to be greater than another

      希望对你有帮助!

      【讨论】:

        猜你喜欢
        • 2020-06-24
        • 2019-08-19
        • 2016-07-10
        • 2015-08-17
        • 2018-09-03
        • 1970-01-01
        • 1970-01-01
        • 2011-09-28
        • 1970-01-01
        相关资源
        最近更新 更多