Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Check Whether an Email Address Is Valid in Java

See the following code.

String email = "test@test.com";
Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
Matcher m = p.matcher(email);
boolean matchFound = m.matches();
if(matchFound){
    System.out.println("EMAIL OK");
}else{
    System.out.println("EMAIL ERROR");
}

Comments