본문 바로가기
왕초보 개발일지/기타

비밀번호 유효성 체크로직

by n년차초보개발자 2023. 10. 26.
728x90
반응형

//숫자 + 문자
public static boolean containsNumberAndLetter(String sentence) {
        // 정규 표현식 패턴 설정
        String pattern = "(?=.*[0-9])(?=.*[a-zA-Z]).*";
        // 문장과 패턴 매칭
        Pattern regex = Pattern.compile(pattern);
        Matcher matcher = regex.matcher(sentence);
        // 매칭 결과 반환
        return matcher.matches();
 }

//숫자 + 특수문자
    public static boolean containsNumberAndSpecialChar(String sentence) {
        // 정규 표현식 패턴 설정
        String pattern = "(?=.*[0-9])(?=.*[^a-zA-Z0-9\\s]).*";
        // 문장과 패턴 매칭
        Pattern regex = Pattern.compile(pattern);
        Matcher matcher = regex.matcher(sentence);
        // 매칭 결과 반환
        return matcher.matches();
    }

//숫자+특수문자+영문
public static boolean containsNumberLetterAndSpecialChar(String sentence) {
    // 정규 표현식 패턴 설정
    String pattern = "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9\\s]).*$";
    
    // 문장과 패턴 매칭
    Pattern regex = Pattern.compile(pattern);
    Matcher matcher = regex.matcher(sentence);
    
    // 매칭 결과 반환
    return matcher.matches();
}


if(!(containsNumberAndLetter(password)))  {//영문+숫자 체크

 return;

}

if(containsNumberAndSpecialChar(password))  {//숫자+특수문자 체크

return
}

if(!containsNumberLetterAndSpecialChar(password))  {//세개 한번에 체크

return
}

728x90
반응형

'왕초보 개발일지 > 기타' 카테고리의 다른 글

SQLD 보수교육  (41) 2024.04.18
크롬 Don't paste code 오류  (1) 2024.04.12
크로스도메인 이슈해결  (0) 2023.06.13
select update한번에 하기  (0) 2023.06.13
web.xml 작성순서  (0) 2023.02.24

댓글