67

in simple use rules of laravel validator i want to check input for between 1 and 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',
6
  • 2
    It's just between:min,max not digits_between See: laravel.com/docs/validation#rule-between Commented Mar 10, 2014 at 14:16
  • 1
    @FDL this required|integer|between:1,10 is correct. thanks Commented Mar 10, 2014 at 14:19
  • Added as answer so the question can be closed. Glad you got it sorted. Commented Mar 10, 2014 at 14:21
  • @naththedeveloper between does not work without the integer rule Commented Jun 6, 2017 at 11:39
  • @peter my answer has integer in it... see the answer not the comment Commented Jun 6, 2017 at 12:28

3 Answers 3

134

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

'item' => 'required|integer|between:1,10',
Sign up to request clarification or add additional context in comments.

6 Comments

just saying that using digits_between costed in my application some stolen bitcoins, because digits_between does not work at all. now your answer works well.
For some reason 'item' => 'between:1,10 doesn't work
Between works, you just need to have the integer validation as well.
for simple : 'item' => 'required|between:1,10', will work
Data range example from 1 to 100, then use like 'item' => 'min:1,max:100'. It will work :)
|
28

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.

'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.

'item' => 'required|numeric|between:1,2',

1 Comment

I think the Ideal answer is not the correct one but the the comparative and descriptive of wrong vs right + the right one , thanks
2

Try This way

'your_number' => ['required', 'integer', 'between:1,10']

Or

'your_number' => 'required|digits_between:1,10'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.