Validation 如何验证Laravel中的确切单词?
Laravel中的验证类是否验证确切的单词 乙二醇Validation 如何验证Laravel中的确切单词?,validation,laravel,Validation,Laravel,Laravel中的验证类是否验证确切的单词 乙二醇 其中字段的值必须为“hello”。是。我至少知道两种方法 // option one: 'in' takes a comma-separated list of acceptable values $rules = [ 'field' => 'in:hello', ]; // option two: write a matching regular expression $rules = [ 'field' =>
其中字段的值必须为“hello”。是。我至少知道两种方法
// 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$',
];
事实上,我不记得您是否需要正则表达式中的^$分隔符,但很容易通过尝试找到它。:) 更新了Laravel 5.5的方法。
使用规则代码>控制器中的命名空间以访问规则类(illumb\Validation\Rule)
谢谢,“in”是我想要的。
// 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$',
];
// 'in' takes an array of values
$rules = [
'field' => [ Rule::in('hello')]
];