validate codeigniter 3 code example

Example 1: codeigniter form_validation email

$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

Example 2: form validation input inside api codeigniter

$this->form_validation->set_rules('user_api_key', 'User Api Id', 'trim|required');

if ($this->form_validation->run() == FALSE) {
  $data = strip_tags($this->form_validation->error_string());
  return $this->json_out($data, 0, $code = 'form_validation_error', $msg = 'Some Fields are required');
}

Example 3: file form validation codeigniter

if (empty($_FILES['userfile']['name']))
{
    $this->form_validation->set_rules('userfile', 'Image', 'required');
}

Example 4: codeigniter validation text length

$this->form_validation->set_rules('ratingMessage', 'Review message', 'trim|max_length[255]|max_length[10]');

 $this->form_validation->set_message('max_length', 'Message you have entered for %s is too long please try again!');

Tags:

Php Example