2

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:[???]'
6
  • It seems you forgot to include a question in your question. Commented Mar 9, 2015 at 7:34
  • I have tried this but its not working 'status' => 'required|regex:[Approved|Pending]' Commented Mar 9, 2015 at 7:37
  • I want status value to be only 'Approved' or 'Pending' Commented Mar 9, 2015 at 7:38
  • Still not really a question, but you should have included that from the beginning. Commented Mar 9, 2015 at 7:38
  • Please tell me whats missing ? Commented Mar 9, 2015 at 7:41

1 Answer 1

5

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.