feat: add email validator

This commit is contained in:
Anthony Berg 2024-10-15 15:25:58 +02:00
parent ca250b3718
commit c37111f7a5

17
src/EMail.java Normal file
View File

@ -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 <code>true</code> if the email is correctly formatted, otherwise <code>false</code>
*/
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();
}
}