Java examples for java.util.regex:Match Email
is a string representing an Email
import java.util.regex.Pattern; public class Main { public static void main(String[] argv) { String email = "java2s.com"; System.out.println(isEmail(email)); //from ww w . j a va2s.com email = "asdf@java2s.com"; System.out.println(isEmail(email)); } private final static Pattern EMAIL = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"); public static boolean isEmail(String email) { return !isEmpty(email) && EMAIL.matcher(email).matches(); } public static boolean isEmpty(String str) { return str == null || str.trim().length() == 0 || str.trim().equalsIgnoreCase("null"); } }