Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel set between digits in validation

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', 
like image 636
DolDurma Avatar asked Mar 10 '14 14:03

DolDurma


People also ask

What is bail in laravel validation?

The bail validation rule applies to a "multi-rule" attribute. It does not stop running validation for other attributes. From the documentation: $request->validate([ 'title' => 'bail|required|unique:posts|max:255', 'body' => 'required', ]);

How do you validate exact words in laravel?

To get the exact words to validate you can make use of Rule::in method available with laravel. Using Rule::in method whatever the values provided by this rule has to be matched otherwise it will fail.

What is the method used to configure validation rules in form request laravel?

Laravel Form Request class comes with two default methods auth() and rules() . You can perform any authorization logic in auth() method whether the current user is allowed to request or not. And in rules() method you can write all your validation rule.


2 Answers

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

'item' => 'required|integer|between:1,10', 
like image 189
naththedeveloper Avatar answered Sep 30 '22 17:09

naththedeveloper


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', 
like image 28
Saeed Avatar answered Sep 30 '22 18:09

Saeed