php - Extending Validation Library - CI2 -


i need set validation student id's , ci native library not cutting it, extended. having issue getting work, , don't quite know goofing up. first crack @ regex go easy on me. here code :

<?php   if(!defined('basepath')) exit('no direct script access allowed');   class my_form_validation extends ci_form_validation  {       public function is_valid_student_id($str)      {          if(strlen($str) > 9)          {              $this -> set_message('is_valid_student_id', 'a-number can not on 9 characters');              return false;          }          elseif(strlen($str) < 9)          {              $this -> set_message('is_valid_student_id', 'a-number can not under 9 characters');              return false;          }          elseif((($str[0]) !== 'a') && (($str[0]) !== 'a'))          {              $this -> set_message('is_valid_student_id', 'a-number must begin letter "a"');              return false;          }          elseif(ctype_alpha($str[0]))          {              if(is_numeric(substr($str, 1, strlen($str) - 1)))              {                  return true;              }              else              {                  $this -> set_message('is_valid_student_id', 'a-number must have 8 digits 0 - 9');                  return false;              }          }          else          {              $this -> set_message('is_valid_student_id', 'a-number must begin letter "a"');              return false;          }       }   } 

then use validation :

if (!$this->input->post('student') == 'yes') {     $this->form_validation->set_rules('anum', 'a number', 'required|is_valid_student_id|exact_length[9]'); } 

i've been following these good /// tutorials, still little confused. great. thank you

if you're using callback_ syntax, function called needs on controller. if you're adding form_validation library directly, though, don't need callback_. try this:

$this->form_validation->set_rules(       'anum', 'a number', 'required|is_anum|exact_length[9]'); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -