我按照教程 http://dialect.ca/code/ci-simple-login-secure/ 但是输入密码时出现密码错误
M@ndiri%%321 and M@ndiri%%654
无论如何已经扭转了我的密码错误..如果正则表达式有问题?
怎么解决???...谢谢
我按照教程 http://dialect.ca/code/ci-simple-login-secure/ 但是输入密码时出现密码错误
M@ndiri%%321 and M@ndiri%%654
无论如何已经扭转了我的密码错误..如果正则表达式有问题?
怎么解决???...谢谢
根据上面显示的正则表达式,除了字母数字字符之外你不应该有任何东西,但正如你所看到的,你的密码字符串中有一些特殊字符:)
上面的表达式也可以这样写/([a-zA-Z0-9]+)/g
。或者像这样/([[:alnum:]+])/g
如果要添加特殊字符,请使用 this /([ -~]+)/g
。这将允许您使用(英文)字母数字和特殊字符。
或者,/([a-zA-Z0-9%@#$]+)/g
如果您想允许字母数字和仅在您的评论中提到的特殊字符,请使用此选项。
如何在 PHP 中使用上述模式
$password = "aH8J9%3$%";
if(!preg_match("/^([a-zA-Z0-9%@#$]+)$/", $password)){
echo "Invalid password!";
}
如何在 JavaScript 中使用它
var pattern = /^([a-zA-Z0-9%@#$]+)$/g;
var password = document.getElementById("password").value; // aH8J9%3$%
if(!pattern.test(password)){
alert("Invalid password!");
}