Sunday, 25 June 2017

php - Laravel Input validation Between is not validate correctly



currently i'm facing some issue in laravel input validation where the validation rules for between seems like doesnt apply correctly. Below is my HTML code.















What i'm trying to do is to validate the given price must be between 0 and 9999.99. I inspect element and remove the min="0" and try to submit with negative value says -1000, the system seems to accept the input. Below is my validator rules



$validator = Validator::make($request::all(),

[
'thread_title' => 'required|max:100',
'thread_item_price' => 'between:0,9999.99'
],
[
'thread_title.required' => 'Please fill in thread title.',
'thread_title.max' => 'Thread title has exceeded 100 characters.',
'thread_item_price.required' => 'Price cannot be empty.',
'thread_item_price.between' => 'Price must be equals to 0 or 9999.99.',
]);


if ($validator->fails()) {
return Redirect::back()
->withErrors($validator)
->withInput();
};


Am i doing something wrong and make the validation failed?


Answer




You need to let Laravel know that it's a numeric value. This should work for you.



'thread_item_price' => 'numeric|between:0,9999.99'

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...