Php 密码Regex-Gov-Reqs
对于政府总承包商,希望根据其要求应用密码正则表达式:Php 密码Regex-Gov-Reqs,php,mysql,regex,Php,Mysql,Regex,对于政府总承包商,希望根据其要求应用密码正则表达式: 至少有一个大写字母 至少有一个小写字母 至少一个数字 至少有一个特殊字符 具有以下代码: if(empty(trim($_POST["password"]))) { $passwordErr = "Please enter a password."; } elseif(trim($_POST["password"]) === $username) { $passwordErr = "Cannot be the
if(empty(trim($_POST["password"]))) {
$passwordErr = "Please enter a password.";
} elseif(trim($_POST["password"]) === $username) {
$passwordErr = "Cannot be the same as your username";
} elseif(trim_check($_POST["password"]) == TRUE) {
$passwordErr = "Please do not use a space in your password.";
} elseif(!preg_match('/^(?=.*\d)(?=.*[\x21-\x7E])(?=.*[a-z])(?=.*[A-Z])[0-9A-Za-z\x21-\x7E]{6,50}$/',($_POST['password']))) {
$passwordErr = "Must be six to fifty characters in length and at least one of each: <ul><li><strong>Uppercase</strong></li><li><strong>Lowercase</strong></li><li><strong>Number</strong></li><li><strong>Special Character</strong></li></ul>";
} else {
$password = trim($_POST['password']);
}
我想问两件事:
\x21-\x7E
(有关我所指的两个部分的含义,请参见#2)[0-9A-Za-z\x21-\x7E]
的这一部分做了什么,这一部分(?=.*\d)(?=.[\x21-\x7E])(?=.[a-z])(?=.[a-z])
还没有做什么-它必须是一个字母、数字和特殊字符(但我觉得这是多余的)这是您当前的正则表达式,为便于阅读,它分为多行:
^
(?=.*\d) \
(?=.*[\x21-\x7E]) \
(?=.*[a-z]) / assert some conditions
(?=.*[A-Z]) /
[0-9A-Za-z\x21-\x7E]{6,50} -- match here
$
前四个肯定的lookahead断言数字、特殊字符、小写和大写字母在模式中出现一次或多次。但问题是,lookaheads断言,但实际上并不匹配或消费任何东西。因此,正则表达式的最后一部分是这样做的:
[0-9A-Za-z\x21-\x7E]{6,50}
请注意,上述内容也仅限于上述类型中的字符,并且只允许使用6到50个字符。Gotcha、assert和match。谢谢看起来语法是正确的,我相信我已经包含了所有必要的ascii字符。谢谢你的时间!
[0-9A-Za-z\x21-\x7E]{6,50}