user1213679
user1213679

Reputation: 269

Laravel validation with comma in the value

I'd like to use Laravel's "in" validation to validate data coming from a "select" input but some of the options in the select might contain comma which is a special character in validation string. Is there a way to escape commas. Eg: if the select has "foo", "bar" and "foo, bar" as option the following Laravel validation doesn't work: "field" => "in:foo,bar,foo, bar"

Thanks for the help

Upvotes: 4

Views: 2313

Answers (1)

milo526
milo526

Reputation: 5083

You can use the Rule facade instead:

use Illuminate\Validation\Rule;

Validator::make($data, [
    'field' => [
        Rule::in(['foo', 'bar', 'foo, bar']),
    ],
]);

More validation logic can be found here.

Upvotes: 3

Related Questions