diff --git a/src/EMail.java b/src/EMail.java index aad9586..0c85ef0 100644 --- a/src/EMail.java +++ b/src/EMail.java @@ -14,4 +14,19 @@ public class EMail { // Checks and returns if the email matches the regex pattern return pattern.matcher(email).matches(); } + + /** + * Retrieves the domain part of the email address + * @param email A valid email address + * @return The domain of the email address from the parameter + */ + public String getDomain(String email) { + // Checks that the email address is valid, otherwise throw exception + if (!validate(email)) { + throw new IllegalArgumentException("The email address provided is not valid"); + } + + // Returns the domain of the email address + return email.split("@")[1]; + } }