Laravel set between digits in validation

PhpLaravelLaravel 4

Php Problem Overview


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

Php Solutions


Solution 1 - Php

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

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

Solution 2 - Php

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDolDurmaView Question on Stackoverflow
Solution 1 - PhpnaththedeveloperView Answer on Stackoverflow
Solution 2 - PhpSaeedView Answer on Stackoverflow