Validate an email address is easy if you have good valid pattern expression.
package com.jsupport; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * * @author JSupport */ public class ValidateEmailAddress { public boolean isValidEmailAddress(String emailAddress) { String expression = "^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; CharSequence inputStr = emailAddress; Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); return matcher.matches(); } public static void main(String[] args) { ValidateEmailAddress vea = new ValidateEmailAddress(); System.out.println(vea.isValidEmailAddress("info@jsupport.info")); // Valide emaill address System.out.println(vea.isValidEmailAddress("info@jsup@port.info")); // Invalide emaill address System.out.println(vea.isValidEmailAddress("info@jsupport.in_fo")); // Invalide emaill address System.out.println(vea.isValidEmailAddress("in@fo@jsupport.info")); // Invalide emaill address System.out.println(vea.isValidEmailAddress("info@jsupport.com.lk")); // Valide emaill address } }
Here you will find how to validate email address using Java Mail API