CI框架set_rules自定义错误

php代码:

//注册
public function register(){
    $this->load->helper('form');

    //切换中文表单验证语言包
    $this->config->set_item('language', 'chinese');//设置语言
    $this->load->library('form_validation');
    $this->form_validation->set_rules('phone','手机号','required|numeric|exact_length[11]|callback_phone_check');

    $yz_status=$this->form_validation->run();
    if($yz_status){//验证通过后保存
       //验证通过代码
    }else{//验证未通过
       //显示模板提示错误
    }
}
//注册时验证手机号是否存在
public function phone_check($str){
    $isExistUser = $this->UsersModel->get_one(array('phone'=>$str),'uid desc');
    if ($isExistUser){
        $this->form_validation->set_message('phone_check', '{field}已存在');
        return FALSE;
    }else{
        return TRUE;
    }
}

 

模板代码:

<div style="line-height: 20px;height: 26px;" id="ck_phone">
   {form_error('phone', '<div class="Tips">', '</div>')}
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值