can anybody tell me how to validate a set of email id 's using java..
Printable View
can anybody tell me how to validate a set of email id 's using java..
You can use the Regular expressions facilities...
Quote:
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.");
}
}
pjmorce, it's better give a guide first, before posting a code segment. Reason is our thread poster can confused as well as he/she doesn't learn new things and like to wait until someone post a code segment for there question in future. :)
You are right.
Here goes a little tutorial explaining the goal of regular expressions and how they can be used with Java...
www regular-expressions.info/java.html
regards
That's really nice lol. :)
The regex posted up thread is at best a decent first pass. The actual format is a lot more complex. Some of the complexity is probably no longer needed, but the official spec is RFC822
RFC 822 (rfc822) - STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES