Java examples for java.util.regex:Match Email
is Email by regex
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) { String searchPhrase = "12312@java2s.com"; System.out.println(isEmail(searchPhrase)); }/* ww w . j a va 2 s .c o m*/ public static boolean isEmail(final String searchPhrase) { if (isNull(searchPhrase)) return false; final String check = "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; final Pattern regex = Pattern.compile(check); final Matcher matcher = regex.matcher(searchPhrase); return matcher.matches(); } public static boolean isNull(String str) { if (str == null || str.length() == 0) { return true; } return false; } }