[eluser]wdcmatt[/eluser]
alpha numeric dash and SPACE!
I searched google for about 20 min and did not find a nice way to do this, i found a few poorly written one line scripts, still not to my liking, here is what I came up with hopefully it can help someone else...
Code:
/**
* Method is used to validate strings to allow alpha
* numeric spaces underscores and dashes ONLY.
* @param $str String The item to be validated.
* @return BOOLEAN True if passed validation false if otherwise.
*/
function _alpha_dash_space($str_in = '')
{
if (! preg_match("/^([-a-z0-9_ ])+$/i", $str_in))
{
$this->form_validation->set_message('_alpha_dash_space', 'The %s field may only contain alpha-numeric characters, spaces, underscores, and dashes.');
return FALSE;
}
else
{
return TRUE;
}
}
And then I use this as a callback
Code:
$this->load->library('validation');
$rules['url_title'] = "required|callback__alpha_dash_space";
$this->validation->set_rules($rules);
Notice the double underscore after callback....
Well in any case I hope this helps someone.