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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:48:52  来源:igfitidea点击:

Laravel set between digits in validation

phplaravellaravel-4

提问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

You seem to be using digits_betweenbut you need to be using just between(docs).

您似乎正在使用,digits_between但您只需要使用between( docs)。

'item' => 'required|integer|between:1,10',

回答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',