How to do a negative form validation in codeigniter?

前端 未结 3 1669
走了就别回头了
走了就别回头了 2021-01-18 09:27

is_unique is the form validation which not allow the value exist in the database. But, can I do the opposite one? for example, I would like to need the value w

3条回答
  •  [愿得一人]
    2021-01-18 09:42

    Try your own callback function

    $this->form_validation->set_rules('email', 'Email', 'required|max_length[32]|valid_email|callback_email_check');
    

    Function will be something like this

    public function email_check($str)
        {
            if ($str == 'test@test.com')
            {
                $this->form_validation->set_message('email_check', 'The %s field can not be the word "test@test.com"');
                return FALSE;
            }
            else
            {
                return TRUE;
            }
        }
    

提交回复
热议问题