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;
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM