Validate Email address in Java
Method to validate email entry in Java.
public static boolean isValidEmailAddress(String enteredEmail) {
boolean isValid = false;
boolean containsDot = false;
boolean containsAt = false;
int dotPosition = 0;
int addPosition = 0;
char addSign = '@';
char dotLetter = '.';
if (enteredEmail != null && !enteredEmail.isEmpty()){
dotPosition = enteredEmail.lastIndexOf(".");
addPosition = enteredEmail.lastIndexOf("@");
if(dotPosition != -1 && addPosition != -1 && dotPosition != 0 && addPosition != 0 && dotPosition != (enteredEmail.length()-1)
&& addPosition != (enteredEmail.length()-1) && dotPosition != (addPosition + 1)
&& dotPosition != (addPosition -1) && addPosition != (dotPosition + 1) && addPosition != (dotPosition - 1)
&& enteredEmail.indexOf(addPosition+1) != dotLetter && enteredEmail.indexOf(addPosition-1) != dotLetter
){
isValid = true;
}
}
return isValid;
}
public static boolean isValidEmailAddress(String enteredEmail) {
boolean isValid = false;
boolean containsDot = false;
boolean containsAt = false;
int dotPosition = 0;
int addPosition = 0;
char addSign = '@';
char dotLetter = '.';
if (enteredEmail != null && !enteredEmail.isEmpty()){
dotPosition = enteredEmail.lastIndexOf(".");
addPosition = enteredEmail.lastIndexOf("@");
if(dotPosition != -1 && addPosition != -1 && dotPosition != 0 && addPosition != 0 && dotPosition != (enteredEmail.length()-1)
&& addPosition != (enteredEmail.length()-1) && dotPosition != (addPosition + 1)
&& dotPosition != (addPosition -1) && addPosition != (dotPosition + 1) && addPosition != (dotPosition - 1)
&& enteredEmail.indexOf(addPosition+1) != dotLetter && enteredEmail.indexOf(addPosition-1) != dotLetter
){
isValid = true;
}
}
return isValid;
}
Comments
Post a Comment