Java examples for java.util.regex:Match Email
Check if a string is email Format via regex
import java.util.regex.Pattern; public class Main{ public static void main(String[] argv){ String email = "java2s.com"; System.out.println(emailFormat(email)); // w w w . j a v a2s . c om email = "asdf@java2s.com"; System.out.println(emailFormat(email)); } public static boolean emailFormat(String email) { String pattern = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; return Pattern.compile(pattern).matcher(email).find(); } }