[eluser]RaGe10940[/eluser]
I need more functionality from CI for student ID's so I want to create my own validation but it is not working period, with any condition. I feel like the function is not even being called.
This is my code :
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 be over 9 characters');
return FALSE;
}
elseif(strlen($str < 9))
{
$this -> set_message('is_valid_student_id', 'A-Number can not be under 9 characters');
return FALSE;
}
elseif((substr($str, 0, 1) !== 'a') || (substr($str, 0, 1) !== 'A'))
{
$this -> set_message('is_valid_student_id', 'A-Number must begin with "A"');
return FALSE;
}
elseif(!preg_match("/^[0-9]/", $str))
{
$this -> set_message('is_valid_student_id', 'A-Number must have 8 digits 0 - 9');
return FALSE;
}
else
{
return TRUE;
}
}
}
Is there anything I am missing?
and this is how I am calling it :
Code:
$this -> load -> library('form_validation');
if(!$this -> input -> post('student') == 'yes')
{
$this -> form_validation -> set_rules('anum', 'A Number', 'required|is_valid_student_id|exact_length[9]');
}
}