1// Java program to check if an email address
2// is valid using Regex.
3import java.util.regex.Matcher;
4import java.util.regex.Pattern;
5
6class Test
7{
8 public static boolean isValid(String email)
9 {
10 String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\."+
11 "[a-zA-Z0-9_+&*-]+)*@" +
12 "(?:[a-zA-Z0-9-]+\\.)+[a-z" +
13 "A-Z]{2,7}$";
14
15 Pattern pat = Pattern.compile(emailRegex);
16 if (email == null)
17 return false;
18 return pat.matcher(email).matches();
19 }
20
21 /* driver function to check */
22 public static void main(String[] args)
23 {
24 String email = "contribute@geeksforgeeks.org";
25 if (isValid(email))
26 System.out.print("Yes");
27 else
28 System.out.print("No");
29 }
30}