我扩展了 CI 表单验证库,如下所示:
class MY_Form_validation extends CI_Form_validation {
function __construct($config = array())
{
parent::__construct($config);
}
function check_first_char($str)
{
$CI =& get_instance();
$first_char = substr($str, 0, 1);
if ($first_char != 'P' || $first_char != 'S')
{
$CI->form_validation->set_message('check_first_char', 'The %s field must begin with P or S!');
return FALSE;
}
else {
return TRUE;
}
}
并像下面这样调用它:
$this->form_validation->set_rules('sponsor_id', 'Sponsor ID', 'trim|required|exact_length[7]|check_first_char');
但它不起作用。我做错了什么?