• CI 配置验证规则



          //判断表单域,提交表单显示对应的错误信息
          $this->load->library('form_validation');
          $config = array(
          array(
          'field' => 'username',
          'label' => '用户名',
          'rules' => 'trim|required|min_length[2]|max_length[12]'    //|xss_clean'
          ), //将用户名通过“xss_clean”函数处理去掉了有害数据。
          array(
          'field' => 'password',
          'label' => '密码',
          'rules' => 'trim|required|md5'
          ),
          array(
          'field' => 'passconf',
          'label' => '再次输入',
          'rules' => 'trim|required|md5|matches[password]'
          ),
          array(
          'field' => 'email',
          'label' => '邮箱',
          'rules' => 'trim|required|valid_email'
          )
          );

          $this->form_validation->set_rules($config);

      $bool = $this->form_validation->run();
          //-----------------------------------------------------------------------------------------------------
          // 第二种规则定义
          // $this->load->library('form_validation');
          // $this->form_validation->set_rules('username', '用户名', 'required|min_length[5]|max_length[12]');
          // $this->form_validation->set_rules('password', '密码', 'required|matches[passconf]');
          // $this->form_validation->set_rules('passconf', '再次输入', 'required');
          // $this->form_validation->set_rules('email', '邮箱', 'required|valid_email');
        //$bool = $this->form_validation->run();

        //-----------------------------------------------------------------------------------------------------

    单独生成一个    form_validation.php   文件,放到【applicationconfig】文件夹下:

    内容为:

      <?php

    /*
     * 配置验证规则
     */
    $config = array(
        'zhuce' => array(
            array(
                'field' => 'username',
                'label' => '用户名',
                'rules' => 'trim|required|min_length[2]|max_length[12]|callback_username_check'    //|xss_clean'
            ), //将用户名通过“xss_clean”函数处理去掉了有害数据。
            array(
                'field' => 'password',
                'label' => '密码',
                'rules' => 'trim|required|md5'
            ),
            array(
                'field' => 'passconf',
                'label' => '再次输入',
                'rules' => 'trim|required|md5|matches[password]'
            ),
            array(
                'field' => 'email',
                'label' => '邮箱',
                'rules' => 'trim|required|valid_email'
            )
        ),
        'login' => array(
            array(
                'field' => 'username',
                'label' => '用户名',
                'rules' => 'trim|required|min_length[2]|max_length[12]'    //|xss_clean'
            ), //将用户名通过“xss_clean”函数处理去掉了有害数据。
            array(
                'field' => 'password',
                'label' => '密码',
                'rules' => 'trim|required|md5'
            )
        )
    );


    调用时:

       $this->load->library('form_validation');
            $bool = $this->form_validation->run('login');
            if ($bool == FALSE) {
          // 返回到注册页面 

         }else{

        //验证没有问题

      }

      

  • 相关阅读:
    rabbitmq 安装和配置
    rabbitmq
    Redis Keys 命令
    python pickle模块
    Redis之Python操作
    flask中的g、add_url_rule、send_from_directory、static_url_path、static_folder的用法
    Python 并行分布式框架 Celery
    Celery+python+redis异步执行定时任务
    feed流拉取,读扩散,究竟是啥?
    DNS解析
  • 原文地址:https://www.cnblogs.com/c-961900940/p/4521507.html
Copyright © 2020-2023  润新知