目前我在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>
我要做的是验证给定的价格必须在0到9999.99之间.我检查元素并删除min =“0”并尝试提交负值表示-1000,系统似乎接受输入.以下是我的验证器规则
$validator = Validator::make($request::all(),
[
'thread_title' => 'required|max:100',
'thread_item_price' => 'between:0,9999.99'
],
[
'thread_title.required' => 'Please fill in thread title.',
'thread_title.max' => 'Thread title has exceeded 100 characters.',
'thread_item_price.required' => 'Price cannot be empty.',
'thread_item_price.between' => 'Price must be equals to 0 or 9999.99.',
]);
if ($validator->fails()) {
return Redirect::back()
->withErrors($validator)
->withinput();
};
我做错了什么并且验证失败了吗?
解决方法:
'thread_item_price' => 'numeric|between:0,9999.99'