0

it is not working, what should i do to make it work ?

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;
}
TarangP
  • 2,711
  • 5
  • 20
  • 41
  • 1
    Possible duplicate of [Form validation rules for regex\_match](https://stackoverflow.com/questions/13982529/form-validation-rules-for-regex-match) – Vishnu Bhadoriya Feb 12 '18 at 06:42
  • 1
    it would be good to know what your input variable $str contains... – dom Feb 12 '18 at 06:43
  • use this https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods – Haseeb Feb 12 '18 at 07:22

1 Answers1

0

use your own validation methods some thing like this

<?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;
                }
        }

}
Haseeb
  • 2,214
  • 1
  • 22
  • 43