我想使用表单验证来要求同时包含字母和数字字符的密码。到目前为止,这是我想到的:
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]|min_length[8]|alpha_numeric');
问题是“alpha_numeric”要求密码仅包含字母或数字,而不需要两者都包含。在这里选择更强的密码选项。
你可以设置一个callback http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks在你的控制器中:
public function password_check($str)
{
if (preg_match('#[0-9]#', $str) && preg_match('#[a-zA-Z]#', $str)) {
return TRUE;
}
return FALSE;
}
然后,更新您的规则以使用它:
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]|min_length[8]|alpha_numeric|callback_password_check');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)