我正在验证下面的数字字段,代码工作正常。它正在检查字符不应超过 2 个或更少,这对我来说很好。
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'id' => 'required|min:2|max:2',
'title' => 'required'
];
}
但是当我添加更多验证规则(例如(数字))时,最小和最大验证规则发生更改,现在正在检查数字不应大于 2...为什么?这是BUG吗?
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'id' => 'required|min:2|max:2|numeric',
'title' => 'required'
];
}
最佳答案
最小和最大规则取决于字段的类型。如果它是一个字符串,它将检查长度。如果它是一个数字,它将检查该值。
因此,如果您只想使用两个字符集的数字
'id' => 'required|min:10|max:99|numeric',
The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value. For files, size corresponds to the file size in kilobytes.
关于Laravel 表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35223676/