On laravel 11 site I need to check decimal values from 0 till 100(with 2 decimals possible) and I do it with rules :
['required', 'numeric', 'between:0,100'],
OR
required|numeric|min:0.01|max:100
but both not works. Which rules are valid ?
"laravel/framework": "^11.9",
Thanks in advance!
3
Answers
regex:/^d{1,2}(.d{1,2})?$|^100(.00?)?$/
: This regular expression allows numbers from 0 to 100, with up to two decimal places.^d{1,2}(.d{1,2})?$
: Matches numbers from 0 to 99.99.|^100(.00?)?$
: Allows the number 100, optionally followed by.0
or.00
.between:0,100
: Ensures that the number is within the range 0 to 100.You can use this, too
You can do this using regex way
If you need this without using regex, you can follow the steps below
Create Custom Validation Rule
Implement Rule Logic
Use Custom Rule