We can validate Email using regularExpression support given by JDK
EmailValidation.java
Download Source Here
EmailValidation.java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.Pattern;
public class EmailValidation{
public static void main(String args[])
{
Pattern pattern;
Matcher matcher;
public static void main(String args[])
{
Pattern pattern;
Matcher matcher;
String email="suraj20p@gmail.com";
String EMAIL_PATTERN = "^[_A-Za-z0-9]+(\\.[_A-Za-z0-9]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
//compile our pattern
pattern = Pattern.compile(EMAIL_PATTERN);
//pass our email to matcher,so that it can be checked whether pattern is matching or not
matcher = pattern.matcher(email);
//check whether string is matched or not
boolean result= matcher.matches();
if(result)
System.out.println("Email Validated Successfully");
else System.out.println("Invalid Email Address");
}
}
String EMAIL_PATTERN = "^[_A-Za-z0-9]+(\\.[_A-Za-z0-9]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
//compile our pattern
pattern = Pattern.compile(EMAIL_PATTERN);
//pass our email to matcher,so that it can be checked whether pattern is matching or not
matcher = pattern.matcher(email);
//check whether string is matched or not
boolean result= matcher.matches();
if(result)
System.out.println("Email Validated Successfully");
else System.out.println("Invalid Email Address");
}
}
Download Source Here
No comments:
Post a Comment