正则表达式验证密码

时间:2014-09-17 21:11:27

标签: regex

我需要一个正则表达式来验证具有以下要求的密码

长度:最少4个字符,最多39个字符 允许的字符:a-z,A-Z,0-9,减号,下划线,at符号和点 附加:不重复和非增量,如' aaaa'或者' 1234'或者' abcd'

^[a-zA-Z0-9@.-_]{4,39}$

1 个答案:

答案 0 :(得分:0)

当然,这可以用冗长的方式完成 毕竟,由你决定什么是连续的 只是充实了这个正则表达式的其余部分:

 # ^(?:(a(?!b)|b(?!c)|c(?!d)|d(?!e)|1(?!2)|2(?!3)|3(?!4)|4(?!5)|[@._-])(?!\1)){4,39}$

 ^ 
 (?:
      (                     # (1 start)
           a
           (?! b )
        |  b 
           (?! c )
        |  c 
           (?! d )
        |  d 
           (?! e )
           # Add the rest of the alphabet here

        |  1 
           (?! 2 )
        |  2 
           (?! 3 )
        |  3 
           (?! 4 )
        |  4 
           (?! 5 )
           # Add the rest of the numbers here

        |  [@._-]  
           # Add any other sequential symbols here

      )                     # (1 end)
      (?! \1 )              # Non-repeating
 ){4,39}
 $
相关问题