I have found this code snippet on some site and it’s a great way to validate an email address in your Java application.

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public static boolean isValidEmailAddress(String strEmailAddress) {
    String expression = "^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
    CharSequence inputStr = strEmailAddress;
    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    return matcher.matches();
}
 

Leave a Reply

Set your Twitter account name in your settings to use the TwitterBar Section.