Archive for the 'Java Email' Category

003: Email Validations Using Regular Expresssions

Kushal Paudyal August 24th, 2010

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 = "xyz@hotmail.com";

     //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.");
     else
       System.out.println("Invalid Email Id.");
  }

}

Related Java Blog Posts




Your Ad Here


Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing – our website does not ask for your credit card and banking information. Happy Surfing!

Blog Widget by LinkWithin

Originally posted 2007-09-22 10:37:01.

  • Share/Bookmark

Next »