Email validator in java
How to validate an email address in using java regular expression. complete source code is available here. If you need to validate an email address through mail then we need to create a java web application.
Here i created a function emailValidator with a parameter type string. the function will return true or false. call the function where ever you need it
Here i created a function emailValidator with a parameter type string. the function will return true or false. call the function where ever you need it
/**
*
* @see
* @param
* @return boolean
* Description : email validator
* Date : Dec 4, 2009
* Coded by : belazy
*/
public boolean emailValidator(String email) {
boolean isValid = false;
String expression = “^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$”;
CharSequence inputStr = email;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}
Please try the code and provide us a feedback
*
* @see
* @param
* @return boolean
* Description : email validator
* Date : Dec 4, 2009
* Coded by : belazy
*/
public boolean emailValidator(String email) {
boolean isValid = false;
String expression = “^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$”;
CharSequence inputStr = email;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}
Please try the code and provide us a feedback
No comments:
Post a Comment
Your feedback may help others !!!