Dev Research Dev Research - 1 month ago 7
Java Question

how to validate particular domain with emailID in java

public static boolean isValidEmail(String emailID) {
String EMAIL_REGEX = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
Boolean b = emailID.matches(EMAIL_REGEX);
return b;

}


this is my code using this code i am able to validate emailID but i want Unique email ID validation whose domain is @itspl.com i.e if user Enter x@gmail.com then it should display wrong Email ID if they Enter X@itspl.com then it show correct please tell me how i will do this .

Answer

Simply restrict your reg ex with the domain like below

 String EMAIL_REGEX = "^[\\w-_\\.+]*[\\w-_\\.]\\@itspl\\.com";
Comments