Reputation: 2549
Hi I've a select box (Currency) where user can select multiple currencies.
How can I have it validates each value to make sure the string min/max length are 3 and also alpha values? I tried only min/max and it thinks only allow at least 3 items and not min/max length of each value.
$this->validate(request(), [
'currencies' => 'required|array'
]);
Upvotes: 0
Views: 1472
Reputation: 39449
You can check currencies
is an array of distinct values, and each value is a 3-character string like this:
'currencies' => 'required|array|min:1',
'currencies.*' => 'distinct|alpha|size:3',
Upvotes: 2
Reputation: 2227
This will check every item in currencies
array
'currencies.*' => 'size:3|alpha_num'
Upvotes: 1