Email Validations Using Regular Expresssions

The following code demonstrates how to validate email using regular expression:

import java.util.regex.*;
class regexSample
  public static void main(String args[])
     //Input the string for validation
     String email = "";

     //Set the email pattern string
     Pattern p = Pattern.compile(".+@.+.[a-z]+");

     //Match the given string with the pattern
     Matcher m = p.matcher(email);

     //check whether match is found
     boolean matchFound = m.matches();

     if (matchFound)
       System.out.println("Valid Email Id.");
       System.out.println("Invalid Email Id.");


[My Video Promotion]
Tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.