Java 判斷密碼是否是大小寫字母、數字、特殊字符中的至少三種

public class CheckPassword {
    //數字
    public static final String REG_NUMBER = ".*\\d+.*";
    //小寫字母
    public static final String REG_UPPERCASE = ".*[A-Z]+.*";
    //大寫字母
    public static final String REG_LOWERCASE = ".*[a-z]+.*";
    //特殊符號
    public static final String REG_SYMBOL = ".*[~!@#$%^&*()_+|<>,.?/:;'\\[\\]{}\"]+.*";
 
    public static boolean checkPasswordRule(String password){
        //密碼爲空或者長度小於8位則返回false
        if (password == null || password.length() <8 ) return false;
        int i = 0;
        if (password.matches(REG_NUMBER)) i++;
        if (password.matches(REG_LOWERCASE))i++;
        if (password.matches(REG_UPPERCASE)) i++;
        if (password.matches(REG_SYMBOL)) i++;
 
        if (i  < 3 )  return false;
 
        return true;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章