在我的项目中。所有挂载可能是int或float或者甚至是double.in数据库量列类型是varchar
并且对于每个用户选择量我有简单的限制,例如,数量必须大于某个值而少于某个值。但是我在laravel中得到了错误验证。
$ps = DB::table('merchant_web_service')->whereCustomerKey($request->input('customer_key'))->first();
/* $ps->minimum_range_buy is 5 and $ps->maximum_range_buy is 10*/
$validate_amount = Validator::make($request->all(),
['amount' => "required|min:$ps->minimum_range_buy|max:$ps->maximum_range_buy"]);
验证器错误是:
"The amount must be at least 10 characters."
我的测试金额值:1000,100.1
答案 0 :(得分:1)
试试这个
$rules = [
'your_field' => 'required|regex:/^\d*(\.\d{2})?$/'
]
答案 1 :(得分:1)
由于您没有为输入数据类型指定任何规则,因此将其验证为字符串。请尝试numeric
和between
规则。
$validate_amount = Validator::make($request->all(),
['amount'=>
"required|numeric|between:$ps->minimum_range_buy,$ps->maximum_range_buy"
]);