我想在模型中设置验证规则,用户只在文本字段中输入特殊字符。请建议我正确解决。
演示代码
public function addValidations()
{
parent::addValidations();
$this->validate['Field name'] = array
(
'notempty' => array
(
'rule' => array('special char', 'msg',),
'allowEmpty' => false,
'message' => 'Enter Special character only.',
),
);
}
答案 0 :(得分:1)
您可以定义Custom Regular Expression Validation
public $validate = array(
'login' => array(
'rule' => '/^[\W]+$/',
'allowEmpty' => false,
'message' => 'Enter Special character only.'
)
)
// '/^[\w.-]+$/' this will allow only special character.