Validating Matching Strings

Neel picture Neel · Jul 15, 2015 · Viewed 15.7k times · Source

When I use the Validation feature in Laravel, how can I add a pre-defined strings that are allowed in an Input?

For example, let's say I want the Input to contain only one of the following: foo,bar,baz, how can I do that?

$validator = Validator::make($credentials, [
      'profile' => 'required|max:255', // Here I want Predefined allowed values for it
]);

Answer

omarjebari picture omarjebari · Feb 2, 2016

Best to use the 'in' validation rule like this:

$validator = Validator::make($credentials, [
      'profile' => ["required" , "max:255", "in:foo,bar,baz"]  
]);