Laravel - validation | The input field should be one of two values

Viewed 7185

I am trying to validate a form request and I want to accept the field say test if only it has a value or ABC or XYZ. How can I achieve this?

I currently have

$request->validate([
    'test' =>  'required|unique:tests',   
]);
2 Answers

You can use regular expression to validate this field

your regular expression for ABC OR XYZ

Code is

 $request->validate([
    'test' =>  'required|unique:tests|regex:/ABC|XYZ/g',   
]);
Related