IT | 개발/JAVA

[java] 이메일 정규식 체크하기

뻔뻔한 개발자 2023. 5. 24. 09:49

 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
 /**
 * Comment  : 정상적인 이메일 인지 검증.
 */

String address = "abc@de.fg"

String regex = "^[_a-z0-9-]+(.[_a-z0-9-]+)*@(?:\\w+\\.)+\\w+$";   
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(email);

if(m.matches()) {
    logger.info(address + ": 정상" );
}else{
    logger.info(address + ": 비정상" );
}

 

테스트 결과

출처: https://solbel.tistory.com/309