4

in my project. all mount maybe int or float or was even double.in database amount column type is varchar and for each choose amount by user i have simple limitation, for example amount must be more than some value and less that some value. but i get error validation in laravel.

$ps = DB::table('merchant_web_service')->whereCustomerKey($request->input('customer_key'))->first();

/* $ps->minimum_range_buy is 5 and $ps->maximum_range_buy is 10*/

$validate_amount      = Validator::make($request->all(), 
            ['amount' => "required|min:$ps->minimum_range_buy|max:$ps->maximum_range_buy"]); 

validator error is:

"The amount must be at least 10 characters."

my test amount values: 1000,100.1

2 Answers 2

4

Since you didn't specify any rule for the input data type, it validates it as a string. Try numeric and between rules.

$validate_amount = Validator::make($request->all(), 
     ['amount'=>
      "required|numeric|between:$ps->minimum_range_buy,$ps->maximum_range_buy"
     ]);
Sign up to request clarification or add additional context in comments.

2 Comments

this values 1000, 10000.0 and 10000.00 supported by numeric ?
Yes numeric is like a decimal data type.
2

try this

$rules = [
'your_field' => 'required|regex:/^\d*(\.\d{2})?$/'
]

3 Comments

for 100.1 i get this message: The amount format is invalid
are you tried numeric validation rule?
amout is not exactly int or float, is support amout values such as 1000 ,1000.1, 1000.02 ?

Your Answer

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