codeigniter form_validation email

PHP
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
if (empty($_FILES['userfile']['name']))
{
    $this->form_validation->set_rules('userfile', 'Image', 'required');
}
Source

Also in PHP: