Codeigniter custom email validation rules Codeigniter custom email validation rules codeigniter codeigniter

Codeigniter custom email validation rules


Sure, how's this?

function index(){    $this->load->helper(array('form', 'url'));    $this->load->library('form_validation');    $this->form_validation->set_rules('email', 'Email', 'required');    $this->form_validation->set_rules('email', 'Email', 'valid_email');    $this->form_validation->set_rules('email', 'Email', 'callback_email_check');    if ($this->form_validation->run() == FALSE)    {        //fail    }    else    {        //success    }}function email_check($str){    if (stristr($str,'@uni-email-1.com') !== false) return true;    if (stristr($str,'@uni-email-2.com') !== false) return true;    if (stristr($str,'@uni-email-3.com') !== false) return true;        $this->form_validation->set_message('email', 'Please provide an acceptable email address.');        return FALSE;}


public function index()    {        $this->load->helper(array('form', 'url'));        $this->load->library('form_validation');        $this->form_validation->set_rules('email', 'Email', 'required|callback_email_check');        if ($this->form_validation->run() == FALSE)        {            $this->load->view('form');        }        else        {            $this->load->view('formsuccess');        }    }    public function email_check($email)    {        if(stristr($str,'@uni-email-1.com') !== false) return true;        if(stristr($str,'@uni-email-2.com') !== false) return true;        if(stristr($str,'@uni-email-3.com') !== false) return true;        $this->form_validation->set_message('email', 'Please provide an acceptable email   address.');        return FALSE;    }


This is actually more related to PHP than CI. Basically, you should string match inserted email address to each ending string you provided. If there is a match - allow registering, if not - output an alert or something and don't allow it.