验证在yii2中接受字母和斜杠(/)

时间:2015-09-04 12:23:41

标签: php yii2

我有一个文本框,我希望这个文本框只接受字母和正斜杠(/)字符。

如何在yii2模型中实现它?

 ['uri', 'match', 'pattern' => '^[a-zA-Z\s]*$']

我在模型中使用过上面的内容。它无法正常工作

3 个答案:

答案 0 :(得分:1)

您可以使用此规则代码而不是您的规则。

['uri', 'match', 'pattern' => '/^[a-zA-Z\/]*$/' ]

答案 1 :(得分:1)

Try This One....

['uri', 'match', 'pattern' => '/^[a-zA-Z/\s]+$/']

答案 2 :(得分:-2)

正则表达式应该类似于yii:

preg_match('|[a-zA-Z/]*|', $string, $matches);  This is just a usage example of the regex for preg_match, of course the regex should work, not using preg_match in your case.
相关问题