From ce51ba85aade4355453a37b7205160fa7a99aa0a Mon Sep 17 00:00:00 2001 From: Anthony Berg Date: Tue, 15 Oct 2024 15:39:28 +0200 Subject: [PATCH] feat: add function to get email domain --- src/EMail.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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]; + } }