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.");
}
}
Hi Folks, This is our blog where in we can post our questions n solutions related to java and share our experience in java programinng.so that we can master in the java.
JAVA N WEB TECH SYLLABUS
Wednesday, October 27, 2010
Email Address Validation Using a Regular Expression
The following code demonstrates how to validate email using regular expression:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment