Check if email address valid or not in Java

Given a string, find if the given string is a valid email or not.

Input : email = ""
Output : Yes

Input : email = ""
Output : No
There is an extra dot before org.

Prerequisite : Regular Expressions in Java
We use below regular expression provided in OWASP Validation Regex repository.

^[a-zA-Z0-9_+&*-] + (?:\\.[a-zA-Z0-9_+&*-]
+ )*@(?:[a-zA-Z0-9-]+\\.) + [a-zA-Z]{2, 7} 




// Java program to check if an email address
// is valid using Regex.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Test
    public static boolean isValid(String email)
        String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\."+
                            "[a-zA-Z0-9_+&*-]+)*@" +
                            "(?:[a-zA-Z0-9-]+\\.)+[a-z" +
        Pattern pat = Pattern.compile(emailRegex);
        if (email == null)
            return false;
        return pat.matcher(email).matches();
    /* driver function to check */
    public static void main(String[] args)
        String email = "";
        if (isValid(email))




This article is contributed by Pranav. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


Please write to us at to report any issue with the above content.