php 数字的 Laravel 规则验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27614936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Rule Validation for Numbers
提问by AngularAngularAngular
I have the following Rule :
我有以下规则:
'Fno' => 'digits:10'
'Lno' => 'min:2|max5' // this seems invalid
But How to have the Rule that
但是如何拥有这样的规则
Fno Should be a Digit with Minimum 2 Digit to Maximum 5 Digit and
Fno 应该是最小 2 位到最大 5 位的数字,并且
Lno Should be a Digit only with Min 2 Digit
Lno 应该是只有最小 2 位的数字
回答by Damien Pirsy
If I correctly got what you want:
如果我正确地得到了你想要的:
$rules = ['Fno' => 'digits_between:2,5', 'Lno' => 'numeric|min:2'];
or
或者
$rules = ['Fno' => 'numeric|min:2|max:5', 'Lno' => 'numeric|min:2'];
For all the available rules: http://laravel.com/docs/4.2/validation#available-validation-rules
对于所有可用规则:http: //laravel.com/docs/4.2/validation#available-validation-rules
digits_between:min,max
The field under validation must have a length between the given min and max.
numeric
The field under validation must have a numeric value.
max:value
The field under validation must be less than or equal to a maximum value. Strings, numerics, and files are evaluated in the same fashion as the size rule.
min:value
The field under validation must have a minimum value. Strings, numerics, and files are evaluated in the same fashion as the size rule.
数字之间:最小,最大
验证字段的长度必须介于给定的最小值和最大值之间。
数字
验证中的字段必须具有数值。
最大值:值
验证字段必须小于或等于最大值。字符串、数字和文件的计算方式与大小规则相同。
最小值:值
验证中的字段必须具有最小值。字符串、数字和文件的计算方式与大小规则相同。
回答by Ripon Uddin
$this->validate($request,[
'input_field_name'=>'digits_between:2,5',
]);
Try this it will be work
试试这个它会工作
回答by Sumit Kumar Gupta
Laravel min
and max
validation do not work properly with a numeric
rule validation. Instead of numeric, min and max
, Laravel provided a rule digits_between
.
Laravelmin
和max
验证无法与numeric
规则验证一起正常工作。取而代之的是numeric, min and max
,Laravel 提供了一个规则digits_between
。
$this->validate($request,[
'field_name'=>'digits_between:2,5',
]);
回答by Peter Krebs
Also, there was just a typo in your original post.
此外,您的原始帖子中只有一个错字。
'min:2|max5'
should have been 'min:2|max:5'
.
Notice the ":" for the "max" rule.
'min:2|max5'
应该是'min:2|max:5'
。
注意“:”代表“max”规则。