Reading the docs, there doesn’t appear to be a way to validate the range of permissible values of numeric (non-integer) inputs. min
and max
validate the number of digits of the number, not the value. See my code:
$request->validate([
'ratio' => 'required|numeric|min:0.01|max:1'; // not limited to 2 decimals
]);
Submitting the form with ratio=0.3333
fails:
The ratio field must not be greater than 1 character.
Is there any way to do what I want with built-in Laravel validation rules, or do I have to write my own?
2
Answers
Oh bother. My question was wrong.
I simplified my code to as simple as I thought possible, but I'd over-simplified it.
My actual code was
which, it turns out, actually doesn't work.
I added
numeric
the second rule, and then it worked.In my opinion, you need to validate this ratio between two values. So, I think this may be useful to you.