Regex for password: repetative characters

前端 未结 4 1729
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 06:59

I have following conditions for password validation.

Password must be at least eight (8) characters in length. Password must contain both alpha and numeric characte

相关标签:
4条回答
  • 2020-12-22 07:50

    How about

    (?>([a-zA-Z])(?!\1)){8,}
    
    0 讨论(0)
  • 2020-12-22 07:57

    The regex to match repeated characters is /(.)\1/.
    I would simply do this as a two-step verification, no need to roll it into one regex.
    As pointed out in the comments, this only lowers password entropy and thereby security though.

    0 讨论(0)
  • 2020-12-22 08:00

    Thanks ..got answer ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*(.)\1).{8}$

    0 讨论(0)
  • 2020-12-22 08:02

    Look aheads are your friend:

    ^(?=.*\d)(?=.*[a-zA-Z])(?!.*(.)\1).{8,}
    
    0 讨论(0)
提交回复
热议问题