diff --git a/src/EMail.java b/src/EMail.java new file mode 100644 index 0000000..aad9586 --- /dev/null +++ b/src/EMail.java @@ -0,0 +1,17 @@ +import java.util.regex.Pattern; + +public class EMail { + /** + * Checks if the email is in a valid format + * @param email The email address being checked + * @return true if the email is correctly formatted, otherwise false + */ + public boolean validate(String email) { + // Set up regex for email format + String emailRegex = "[^@ \\t\\r\\n]+@[^@ \\t\\r\\n]+\\.[^@ \\t\\r\\n]+"; + Pattern pattern = Pattern.compile(emailRegex); + + // Checks and returns if the email matches the regex pattern + return pattern.matcher(email).matches(); + } +}