Validate that password doesn't contain 3+ consecutive characters from name

痴心易碎 提交于 2019-12-04 12:19:34

For your 1,2,3,4 case

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d]{8,}$

For your 5th case

public boolean isValid(final String userName,final String password)
{
    for(int i=0;(i+2)<userName.length();i++)
          if(password.indexof(userName.substring(i,i+2))!=-1)
                return false;
    return true;
}

The last point is not something you do with regex. Loop through the name and check against the password instead.

Regex is good at patterns, not parsing. One way or another you have to use a loop to go through the name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!