Reputation: 5332
I want to add a validation rule for a String to exactly match on any of the Strings provided in a regex pattern. For example, status
must be exactly 'Approved' or 'Pending' and nothing else.
'status' => 'required|regex:[???]'
Upvotes: 2
Views: 2843
Reputation: 152890
You can just use the in
validation rule.
in:foo,bar,...
The field under validation must be included in the given list of values.
In your case that would be:
'status' => 'required|in:Approved,Pending'
Upvotes: 5