1

I am trying to ensure a field is valid if the value appears in a predefined array, but it's not working for me.

The validation rule I am using is:

'title' => [
     'required',
     'in' => ['Mr', 'Mrs', 'Miss', 'Ms'],
],

But it seems to pass validation if I enter an invalid value, such as "Dr".

Anyone know the correct way to do this?

1 Answer 1

3

Try with a string validation rule instead of array:

'title' => 'required|in:Mr,Mrs,Miss,Ms';
Sign up to request clarification or add additional context in comments.

1 Comment

it will work for one value and not work if the request yields an array .. like checklist . if for other case than this .. this will work . 'title.*' => 'required|in:Mr,Mrs,Miss,Ms'

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.