Ali Shahzad
Ali Shahzad

Reputation: 5332

Laravel 5 validation regex for exact string match

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

Answers (1)

lukasgeiter
lukasgeiter

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

Related Questions