强密码的正则表达式 [英] Strong password regex

查看:152
本文介绍了强密码的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要强大的密码验证的正则表达式

 特殊字符 - 不允许
空间 - 不允许
数字字符 - 至少有一个字符
至少有一个大写字母
场的最小和最大长度 - 6到12个字符
重复的字符 - 允许只有两个重复的字符

我的正则表达式是 ^(?=。* \\ D)(?=。* [AZ])(?=。* [AZ])(?!。* \\ S)(?= (?:?!(\\ W)(\\ 1 {2}))+){6,12} $
但是却忽略了特殊字符(如加?)

请帮帮忙!


解决方案

  ^(?=。* [AZ])(?=。* \\ D)(?!。*( 。)\\ 1 \\ 1)[A-ZA-Z0-9 @] {6,12} $


  • 特殊字符 - 不允许

  • 空间 - 不允许

  • 最小和领域的最大长度 - 6到12个字符结果
    通过满足[A​​-ZA-Z0-9 @] {6,12}

  • 数字字符 - 至少有一个字符结果
    由<一个满足href=\"http://stackoverflow.com/questions/2973436/regex-lookahead-lookbehind-and-atomic-groups/2973609#2973609\">positive前瞻 (?=。* \\ D)

  • 在至少一个大写字母搜索
    通过积极的前瞻满足(?=。* [A-Z])

  • 重复字符 - 允许只有两个重复的字符结果
    我不知道你这个是什么意思。负前瞻(?!*(。)\\ 1 \\ 1)确保没有字符被允许在连续出现两次以上。子 AA 是好的, AAA 不是。结果
    (?!*(。+)\\ 1 \\ 1)拒绝长度的重复子不止一个(如 ABABAB )或添加。* \\ 1 拒绝非连续多次出现过。

I need strong password validation regex

Special Characters - Not Allowed
Spaces - Not Allowed
Numeric Character - At least one character
At least one Capital Letter 
Minimum and Maximum Length of field - 6 to 12 Characters
Repetitive Characters - Allowed only two repetitive characters

my Regex is ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s)(?=(?:(\w)(?!\1{2}))+).{6,12}$ but it ignores special characters (where to add?)

Please help!

解决方案

^(?=.*[A-Z])(?=.*\d)(?!.*(.)\1\1)[a-zA-Z0-9@]{6,12}$

  • Special Characters - Not Allowed
  • Spaces - Not Allowed
  • Minimum and Maximum Length of field - 6 to 12 Characters
    Met by [a-zA-Z0-9@]{6,12}
  • Numeric Character - At least one character
    Met by positive lookahead (?=.*\d)
  • At least one Capital Letter
    Met by positive lookahead (?=.*[A-Z])
  • Repetitive Characters - Allowed only two repetitive characters
    I am not sure what you mean by this. The negative lookahead (?!.*(.)\1\1) makes sure that no character is allowed to appear more than two times in a row. Substring aa is okay, aaa is not.
    Make it (?!.*(.+)\1\1) to reject repeated substrings of length more than one (like ababab) or add .* before \1 to reject non-continuous repeated appearances too.

这篇关于强密码的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆