php-如何在codeigniter验证中允许使用空格,逗号,点和字母

在我的视图页面中,我有一个用于输入评论的文本框.在我的代码点火器验证中
只允许使用alpha.

我需要在评论字段中允许使用空格,逗号,点,连字符.
这个在我的验证中如何设置规则

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

解决方法:

要进行自定义验证,您将需要使用callback函数.

// 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');

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...