Gonadey
Gonadey

Reputation: 23

Validation range in laravel

I get stuck on laravel. My goal is to create a validation rule to forbid values between 5000 and 7000.
I've tested a lot of things like not_in:range(8000,9000)but I didn't make it. Anyone have any ideas?
Thank you in advance.

Upvotes: 1

Views: 695

Answers (2)

StealthTrails
StealthTrails

Reputation: 2415

You have to create a custom validation rule as mentioned in the official docs


Validator::extend('no_in_range', function($attribute, $value, $parameters)
{
    return (($value < 5000) && ($value > 7000)) ? true : false;
});

I have not tested this code but this is what you are looking for. Please make adjustments as per your need.

Then you can just use no_in_range as other validation methods.


'field' => 'no_in_range'

Upvotes: 1

ivva
ivva

Reputation: 2949

'field' => 'between:5000,7000'

Is this what you need?

Upvotes: 0

Related Questions