本文介绍了如何验证Laravel中的确切单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Laravel中的验证类会验证确切的单词吗?
Does the validation class in Laravel validate exact words?
例如
$rules = [
"field" => "hello"
]
该字段的值必须为"hello".
Where the value of the field must be "hello".
推荐答案
是.我至少知道两种方式.
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. :)
这篇关于如何验证Laravel中的确切单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!