Welcome Guest, Not a member yet? Register   Sign In
[Solved] Regex Check Codeigniter Form Validation
#1

(This post was last modified: 11-06-2015, 02:50 PM by wolfgang1983.)

In codeigniter callback form validation

How can I check if $password has at least one upper case letter?

PHP Code:
<?php

class Login extends CI_Controller {

    public function 
__construct() {
        
parent::__construct();
    }

    public function 
index() {    
        
$data['title'] = 'Administration';

        
$this->form_validation->set_rules('username''Username''trim|required');
        
$this->form_validation->set_rules('password''Password''trim|required|callback_regex');

        if (
$this->form_validation->run() == FALSE) {

            
$this->load->view('common/header.tpl'$data);
            
$this->load->view('common/login.tpl'$data);
            
$this->load->view('common/footer.tpl');

        } else {

            
redirect('common/dashboard');

        }
    }

    public function 
regex($password) {
        if (
$password == FALSE) {
            
$this->form_validation->set_message('regex''Password must contain at least one upper case letter');
            return 
false;
        } else {
            return 
true;
        }
    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
[Solved] Regex Check Codeigniter Form Validation - by wolfgang1983 - 11-05-2015, 06:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB