在我的视图页面中,我有一个用于输入评论的文本框.在我的代码点火器验证中
只允许使用alpha.
我需要在评论字段中允许使用空格,逗号,点,连字符.
这个在我的验证中如何设置规则
$this->form_validation->set_rules('e_comment', 'Comments', 'required|alpha');
解决方法:
// validation rule
$this->form_validation->set_rules('comment', 'Comments', 'required|callback_customAlpha');
// callback function
public function customAlpha($str)
{
if ( !preg_match('/^[a-z .,\-]+$/i',$str) )
{
return false;
}
}
// custom error message
$this->form_validation->set_message('customAlpha', 'error message');