[eluser]CroNiX[/eluser]
Callback functions can only be defined in the controller where they are used in the form validation. You can extend the Form_validation library with your own custom rules and then those could be used anywhere. You also need to define the error message for that rule or nothing will be displayed and the user won't know what field didn't pass validation.
/application/libraries/MY_Form_validation.php
Code:
class MY_Form_validation extends CI_Form_validation
{
function __construct()
{
parent::__construct();
}
//Your custom rules below
function check_state_license_number($license_number)
{
//if passes, return true
if ( preg_match('/^([0-9]{10})$/', $license_number)||preg_match('/^([0-9]{11})$/', $license_number))
{
return TRUE;
}
//didn't pass, set error message for this rule and return FALSE for fail
$this->set_message('check_state_license_number', 'The %s field is not a valid license number.');
return FALSE;
}
}
Now this is no longer a "callback", but a regular rule. So when setting the validation rules just leave off "callback_", like:
Code:
'rules' =>'required|check_state_license_number'