我正在寻找一个正则表达式来验证以下密码:
密码必须包含以下四个类别中至少三个的字符:
我的尝试如下:
position:absolute bottom:0;
这不会检查特殊字符,我也不知道如何使密码必须包含以下四个类别中至少三个的字符。
任何人都可以帮助建议正则表达式来验证此密码策略吗?
答案 0 :(得分:4)
^(?:(?=.*?[A-Z])(?:(?=.*?[0-9])(?=.*?[-!@#$%^&*()_[\]{},.<>+=])|(?=.*?[a-z])(?:(?=.*?[0-9])|(?=.*?[-!@#$%^&*()_[\]{},.<>+=])))|(?=.*?[a-z])(?=.*?[0-9])(?=.*?[-!@#$%^&*()_[\]{},.<>+=]))[A-Za-z0-9!@#$%^&*()_[\]{},.<>+=-]{7,50}$
要更好地查看图像,您可以右键单击图像并在新窗口中选择视图。
此正则表达式将执行以下操作
A-Z
,a-z
,0-9
和!@#$%^&*()_[\]{},.<>+=-
字符A–Z
a–z
0–9
!@#$%^&*()_[]{},.<>+=-
现场演示
https://regex101.com/r/jR9cC7/1
示例文字
1 2 3 4 5 6
12345678901234567890123456789012345678901234567890124567890
aaaaAAAA1111
aaaaBBBBBBB
AAAAaaaa__
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!A
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!A
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!AA
允许使用字符串
aaaaAAAA1111
AAAAaaaa__
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!A
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[A-Z] any character of: 'A' to 'Z'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[0-9] any character of: '0' to '9'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[- any character of: '-', '!', '@',
!@#$%^&*()_[\] '#', '$', '%', '^', '&', '*', '(',
{},.<>+=] ')', '_', '[', '\]', '{', '}', ',',
'.', '<', '>', '+', '='
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[a-z] any character of: 'a' to 'z'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[0-9] any character of: '0' to '9'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[- any character of: '-', '!', '@',
!@#$%^&*()_[ '#', '$', '%', '^', '&', '*', '(',
\]{},.<>+=] ')', '_', '[', '\]', '{', '}',
',', '.', '<', '>', '+', '='
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[a-z] any character of: 'a' to 'z'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[0-9] any character of: '0' to '9'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
[- any character of: '-', '!', '@', '#',
!@#$%^&*()_[\]{} '$', '%', '^', '&', '*', '(', ')',
,.<>+=] '_', '[', '\]', '{', '}', ',', '.',
'<', '>', '+', '='
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
[A-Za-z0- any character of: 'A' to 'Z', 'a' to 'z',
9!@#$%^&*()_[\]{},.< '0' to '9', '!', '@', '#', '$', '%', '^',
>+=-]{7,50} '&', '*', '(', ')', '_', '[', '\]', '{',
'}', ',', '.', '<', '>', '+', '=', '-'
(between 7 and 50 times (matching the most
amount possible))
----------------------------------------------------------------------
$ before an optional \n, and the end of a
"line"
----------------------------------------------------------------------
答案 1 :(得分:0)
为了在一个正则表达式中添加多个条件,我们使用管道或括号 /(regex1)|(regex2)|(regex2)/或(regex1)(regex2)
每个正则表达式条件都非常基本,并且您提出的每个条件都有很多示例。
你可以看看这里: