我不清楚php的正则表达式。我想用以下规则验证密码:
有人可以帮助我吗?
答案 0 :(得分:2)
public function checkPassword($pwd, &$errors) {
$errors_init = $errors;
if (strlen($pwd) < 8) {
$errors[] = "Password too short!";
}
if (!preg_match("#[0-9]+#", $pwd)) {
$errors[] = "Password must include at least one number!";
}
if (!preg_match("#[a-zA-Z]+#", $pwd)) {
$errors[] = "Password must include at least one letter!";
}
return ($errors == $errors_init);
}
答案 1 :(得分:2)
您可以使用此正则表达式:
preg_match('/(^(?=.*\d)(?=.*[a-z]).{8,}$)/i', $password);
详细信息:
(?=.*\d)
:至少一位数(?=.*[a-z])
:至少一封信.{8,}
:8个或更多字符/i
:不区分大小写的正则表达式
答案 2 :(得分:0)