I have this method:
public static boolean esEmail(String correo)
{
Pattern pat = null;
Matcher mat = null;
pat = Pattern.compile("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$");
mat = pat.matcher(correo.trim());
if (mat.find()) {
return true;
}else{
return false;
}
}
but I want it to validate if the address they provide contains "site.com" after the @
I modified the pat:
pat = Pattern.compile("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@+(\\sitio.com)$");
Can you tell me if the change is correct, or if it needs to be modified because when I use it, it only returns false
Thank you
It should just be:
to include addresses that may contain "." but containing characters from a-z (lowercase, not sure if you want this), numbers 0-9, "@" and the domain.
I suggest you add that it also accept capital letters:
In this question on the English site you can see several methods:
https://stackoverflow.com/questions/14817182/validate-only-a-specific-email-with-regex-in-java/14817284#14817284