Home » Php » php – Laravel set between digits in validation

php – Laravel set between digits in validation

Posted by: admin April 23, 2020 Leave a comment

Questions:

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',
How to&Answers:

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

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

Answer:

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