php Laravel 在验证中的数字之间设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22302472/
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 set between digits in validation
提问by DolDurma
in simple use rules of laravel validator i want to check input for between 1 and 10.
在laravel验证器的简单使用规则中,我想检查1到10之间的输入。
this below role do not work correctly and accept zero
以下角色无法正常工作并接受零
'required|integer|digits_between:1,10'
or
或者
'display_post_count' => 'required|min:1|max:10',
回答by naththedeveloper
回答by Saeed
You should use digits_between when you are trying to get exact same "length". for example to validate if user input is a digit between 0 to 99, you just add "digits_between:1,2" in your validation.
当您试图获得完全相同的“长度”时,您应该使用digits_between。例如要验证用户输入是否是 0 到 99 之间的数字,您只需在验证中添加“digits_between:1,2”。
'item' => 'required|digits_between:1,2',
If your number is decimal, and want to validate if entered number is a range number between 1, 1.1, 1.2, 1.3, ... to 2, you need use "numeric|between:1,2" in your validation.
如果您的数字是十进制,并且想要验证输入的数字是否是 1、1.1、1.2、1.3、...到 2 之间的范围数字,则您需要在验证中使用“numeric|between:1,2”。
'item' => 'required|numeric|between:1,2',

