0
votes

I'm validating a Codeigniter form with the following rules:

$this->form_validation->set_rules('friend1', $this->lang->line('friend1'), 'required|callback_valid_email_or_default[friend1]');

I would like my callback function to return TRUE if the value of the field is the default one (i.e. "Email 1") or if the email is a valid one. This way, the validation will pass if the email is correct or if the value hasn't been changed.

My current callback looks like this:

public function valid_email_or_default($input_value, $field){
     if ($input_value == $this->lang->line($field)) {
//Here I need to add something like ||valid_email
         return TRUE;
     }
     else {
         return FALSE;
     }
}

I would like to re-use the valid_email rule from CI.

1

1 Answers

0
votes

I couldn't find a proper way to call valid_email so I solved it using the native filter_var PHP function:

filter_var($input_value, FILTER_VALIDATE_EMAIL)