簡體   English   中英

使用CodeIgniter和Pregmatch表單驗證的自定義錯誤消息

[英]Custom error message using CodeIgniter and Pregmatch Form Validation

它不起作用,我應該怎么做才能使其起作用?

if (preg_match('(?=.*[a-z])(?=.*[A-Z]).*', $str)) 
{
    return TRUE;
}
else
{
    $this->form_validation->set_message('user_password1', 'Please provide a stronger password');
    return FALSE;
}

使用您自己的驗證方法是這樣的

<?php

class Form extends CI_Controller {

        public function index()
        {
                $this->load->helper(array('form', 'url'));

                $this->load->library('form_validation');

                $this->form_validation->set_rules('password', 'Password', 'required|callback_password_check');


                if ($this->form_validation->run() == FALSE)
                {
                        $this->load->view('myform');
                }
                else
                {
                        $this->load->view('formsuccess');
                }
        }

        public function password_check($str)
        {
                if (preg_match('(?=.*[a-z])(?=.*[A-Z]).*', $str))
                {
                    return TRUE;
                }
                else
                {
                    $this->form_validation->set_message('password_check' , 'Please provide a stronger password');
                    return FALSE;
                }
        }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM