Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 之间的Laravel输入验证未正确验证_Php_Validation_Laravel - Fatal编程技术网

Php 之间的Laravel输入验证未正确验证

Php 之间的Laravel输入验证未正确验证,php,validation,laravel,Php,Validation,Laravel,目前,我在laravel输入验证中遇到了一些问题,中间的验证规则似乎没有正确应用。下面是我的HTML代码 <input type="hidden" name="_token" value="{{ csrf_token() }}"> <div class="margin-bottom-10"> <label>Thread Title :</label>

目前,我在laravel输入验证中遇到了一些问题,中间的验证规则似乎没有正确应用。下面是我的HTML代码

<input type="hidden" name="_token" value="{{ csrf_token() }}">
                <div class="margin-bottom-10">
                    <label>Thread Title :</label>
                    <input name="thread_title" maxlength="100" required>
                </div>                  
                <div class="margin-bottom-10">
                    <label>Price :</label>
                    <input type="number" step="0.01" min="0" required title="Please enter price with x.xx format." name="thread_item_price" />
                </div>

我是否做错了什么,导致验证失败?

规则之间只接受整数作为数字。您应该使用浮点数规则

编辑: 我不知道为什么Laravel接受它,验证规则在使用函数之间使用。您可以尝试使用正则表达式规则:

['thread_item_price' => 'regex:/^\d{0,4}\.\d{2}$/'];

您需要让Laravel知道这是一个数值。这应该对你有用

'thread_item_price' => 'numeric|between:0,9999.99'

不需要运行正则表达式
digits\u-between
检查输入的位数,而不是数值
between
起作用,但您需要让Laravel知道这是一个数值,如我的回答所示。注意:基于“between”代码:您没有验证小数点的实际位置数,只是数字在两个实数之间:0和9999.9900000。。。如果您尝试验证9999.981,它将被接受(之后可能四舍五入到9999.98),但如果您尝试使用9999.991,它将失败。
'thread_item_price' => 'numeric|between:0,9999.99'