【发布时间】:2011-11-08 16:32:56
【问题描述】:
好的,我正在为我们的密码策略编写一个密码检查器,它需要 4 个主要分类中的 3 个。我遇到的问题是特殊字符匹配。
这是我目前所拥有的:
private function PasswordRequirements($ComplexityCount) {
$Count = 0;
if(preg_match("/\d/", $this->PostedData['password']) > 0) {
$Count++;
}
if(preg_match("/[A-Z]/", $this->PostedData['password']) > 0) {
$Count++;
}
if(preg_match("/[a-z]/", $this->PostedData['password']) > 0) {
$Count++;
}
// This is where I need help
if(preg_match("/[~`!@#$%^&*()_-+=\[\]{}\|\\:;\"\'<,>.]/", $this->PostedData['password']) > 0) {
$Count++;
}
if($Count >= $ComplexityCount) {
return true;
} else {
return false;
}
}
所以基本上我正在做的是检查每个大小写、数字、大写、小写和特殊字符的字符串。我们对任何特殊字符没有任何限制,我也需要 unicode 字符。 \W 在这种情况下是否有效,还是会再次包含数字?我在 \W 上找不到很好的文档,所以我不清楚这部分。
有谁知道一个简单的正则表达式,它可以涵盖所有特殊字符和不包括数字和字母的 unicode 字符?
任何人都可以免费使用它,因为我认为很多人一直在寻找它。
【问题讨论】:
-
这是一个很好的页面,可以解释您的一些猜测:regular-expressions.info/reference.html
标签: php preg-match special-characters