Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate exact words in Laravel?

Tags:

Does the validation class in Laravel validate exact words?

eg

$rules = [            "field" => "hello"          ] 

Where the value of the field must be "hello".

like image 462
user742736 Avatar asked May 07 '14 05:05

user742736


1 Answers

Yes. I know of at least two ways.

// option one: 'in' takes a comma-separated list of acceptable values $rules = [     'field' => 'in:hello', ];  // option two: write a matching regular expression $rules = [     'field' => 'regex:^hello$', ]; 

Actually, I don't remember if you need the ^$ delimiters in the regex, but it's easy to find out by trying it. :)

like image 171
Joel Hinz Avatar answered Sep 20 '22 19:09

Joel Hinz