如何在codeigniter验证中允许空格,逗号,点和字母表

In my view page.I have a textbox for entering comments.In my codeigniter validation that allow only alpha.

I need to allow space,comma,dot,hyphen in Comment field.. How this place in my validation set rules

    $this->form_validation->set_rules('e_comment', 'Comments', 'required|alpha');

To do custom validation you will need to use a callback function.

// validation rule
$this->form_validation->set_rules('comment', 'Comments', 'required|callback_customAlpha');

// callback function
public function customAlpha($str) 
{
    if ( !preg_match('/^[a-z .,\-]+$/i',$str) )
    {
        return false;
    }
}

// custom error message
$this->form_validation->set_message('customAlpha', 'error message');
function alpha($str)
{
    return ( ! preg_match("/^([-a-z_ ])+$/i", $str)) ? FALSE : TRUE;
} 

In the rules, you can call it like follows:

$this->form_validation->set_rules('comment', 'Comments', required|callback_alpha');

EDIT 01

return ( ! preg_match("/^([-a-z_ .,\])+$/i", $str)) ? FALSE : TRUE;

Change this

Easy and Best way to do this ,

Go to system/library/form_validation.
and make a functions or extend the library:

public function myAlpha($string) 
    {
        if ( !preg_match('/^[a-z .,\-]+$/i',$string) )
        {
            return false;
        }
    }

now use it normally where you want it .

$this->form_validation->set_rules('comment', 'Comments', 'required|myAlpha');