I'm looking to set a validation condition for email whereby after ".xxx" (email termination, e.g: john123@gmail.xxx) the char limit is less than 3 but more than 2 only (e.g: invalid if john123@gmail.c or @gmail.commm).
here is my attempt:
public final boolean validEmail(String target){
boolean valid_dot_com
if(target.toString().contains(".")){
int indexDot = target.toString().indexOf(".");
// substring from char containing "." to last char
String temp = target.toString().substring(indexDot,
target.length());
if(temp.length()<2 && temp.length()>3){
valid_dot_com = false;
}
}
return valid_dot_com && Patterns.EMAIL_ADDRESS.matcher(target).matches();
}
However, this code does not return the result that I needed.
I do have the theory that the Patterns.EMAIL_ADDRESS overwrite my boolean value causing the condition checking to become true even when its not.
Do enlighten me!
Edit:
I've found my answer!
through an online regex generator: https://regex101.com/ I have been able to generate a custom regex pattern to compile and do my validation. Rest of the code is similar to just simple conditions.
Thanks all for the reply!