First of all create a method/function name ‘valid_password’
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | public function valid_password($password=''){ $password = trim($password); $regex_lowercase = '/[a-z]/'; $regex_uppercase = '/[A-Z]/'; $regex_number = '/[0-9]/'; $regex_special = '/[!@#$%^&*()\-_=+{};:,<.>§~]/'; if (empty($password)) { $this->form_validation->set_message('valid_password', 'The {field} field is required.'); return FALSE; } if (preg_match_all($regex_lowercase, $password) < 1) { $this->form_validation->set_message('valid_password', 'The {field} field must be at least one lowercase letter.'); return FALSE; } if (preg_match_all($regex_uppercase, $password) < 1) { $this->form_validation->set_message('valid_password', 'The {field} field must be at least one uppercase letter.'); return FALSE; } if (preg_match_all($regex_number, $password) < 1) { $this->form_validation->set_message('valid_password', 'The {field} field must have at least one number.'); return FALSE; } if (preg_match_all($regex_special, $password) < 1) { $this->form_validation->set_message('valid_password', 'The {field} field must have at least one special character.' . ' ' . htmlentities('!@#$%^&*()\-_=+{};:,<.>§~')); return FALSE; } if (strlen($password) < 5) { $this->form_validation->set_message('valid_password', 'The {field} field must be at least 5 characters in length.'); return FALSE; } if (strlen($password) > 32) { $this->form_validation->set_message('valid_password', 'The {field} field cannot exceed 32 characters in length.'); return FALSE; } return TRUE; } |
callback in Validation rule
1 | $this->form_validation->set_rules('upwd', 'Password', 'required|min_length[5]|callback_valid_password'); |