0

i wrote

$this->form_validation->set_rules(
    'password',
    'password',
    'required|min_length[4]|max_length[8]|regex_match[/^[a-z0-9]+$/]'
);

but I want :
Password must contain exactly 2 special characters and 2 uppercase letters

how to write ?

Beginner
  • 4,118
  • 3
  • 17
  • 26
bhargav Patel
  • 156
  • 12

2 Answers2

3

You can use callback function: Example:

public function password_check($str)
{
   if (preg_match('#[\W]{2}#', $str) && preg_match('#[A-Z]{2}#', $str)) {
     return TRUE;
   }
   return FALSE;
}

And Validation Part:

$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]|min_length[8]|alpha_numeric|callback_password_check');
Nawin
  • 1,653
  • 2
  • 14
  • 23
0

I can provide a special character regularly expression to u:

/[\'.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/

Good luck!

ferry
  • 64
  • 4