[eluser]nealumney[/eluser]
I have a callback function I want to call in a number of controllers, something like this:
Code:
function checkpostcode($postcode)
{
$this->form_validation->set_message('postcode', 'The postcode you entered is not valid');
return preg_match('^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$');
}
For some reason, if I place this in a 'helper' it does not work, but if it is created within the controller it works.
I call the helper before the validation rules are set thus:
Code:
$this->load->helper('checkpostcode');
And my validation rule array entry looks like this:
Code:
array('field' => 'postcode','label' => 'Postcode must be valid','rules' => 'trim|required|callback_checkpostcode'),
Do validation callbacks have to sit within the controller? Or am I doing something wrong?
Thanks
Neal