요즘 사용되는 전자 메일 ID를 확인하고 모든 RFC를 준수하지 않기를 바랍니다. 프로젝트를 위해 우리는 아주 간단한 이메일 검증 도구를 만들었습니다. 왜 ? 아파치와 자바 메일 하나는 정규식을 사용하고 정규 표현식을 영원히 반복 할 수있는 몇 가지 경우가 있습니다. 즉, 클라이언트 처리기 스레드가 루프로 들어가고 사용자에게 빈 화면이 표시됩니다!
그래서 우리는 기본적으로 google/yahoo와 같은 사이트에서와 같이 새로운 이메일 ID를 허용합니다. [email protected]에게 의미
일부 문자 + 하나 개의 점을 우리가 @ 후에 @ 전에 1 개 이상의 문자에 대한 확인 @ 에서 대부분의 일을 확인이어야 점 후 + CHRS
지난 2 년간 아무런 불만이 없었습니다. 또한 도메인을 확인하기 위해 전자 메일을 보내야 할 때 대부분의 경우와 고유 한 토큰 (등록 확인)을 통해 사용자가 전자 메일 ID를 소유하고 있는지 확인해야합니다 (진짜 소유자에게만 메시지를 보낼 수 있음). 그들이 귀하의 사이트를 방문한 경우 클릭하십시오.)
/**
* minimum email [email protected]
* */
public static boolean checkEmail(final String emlId, int dbgPrint) {
// ex:[email protected]
if (emlId == null){
return false;
}
final int lngth = emlId.length();
if (lngth < 6) {
if (dbgPrint > 1) {
System.out.println(" lngth < 6");
}
return false;
}
final int locationAt = emlId.indexOf('@');
if (locationAt < 1) {
if (dbgPrint > 1) {
System.out.println("locationAt < 1 : " + locationAt);
}
return false;//
}
final int postLastPeriod = emlId.lastIndexOf('.');
if (postLastPeriod < 0) {
if (dbgPrint > 1) {
System.out.println("postLastPeriod < 0, locationAt " + locationAt);
}
return false;
}
if (dbgPrint > 1) {
System.out.println(" locationAt " + locationAt + ", postLastPeriod :" + postLastPeriod + " lngth " + lngth);
}
if (lngth - postLastPeriod < 3) {
if (dbgPrint > 1) {
System.out.println(" lngth - postLastPeriod < 2");
}
return false;
}
if (postLastPeriod - locationAt < 1) {
if (dbgPrint > 1) {
System.out.println(" postLastPeriod - locationAt < 1");
}
return false;
}
return true;
}
'ar @ yahoo'이 (가) 틀렸습니까? 일반 최상위 도메인을 호스트 이름으로 사용할 수 있는지 확인합니다. – Matteo
그리고 설명서에 "주소 부분 유효성 검사"라고 쓰여 있으므로'@ '다음의 모든 내용은 무시됩니다. – Matteo
이전 질문에서 Apache Commons가 가장 좋은 도구로 제안되었지만 (http://stackoverflow.com/questions/624581/what-is-the-best-java-email-address-validation-method) 방금 시도했는데 또한 의견을 수락하지 못합니다. – Matteo