commit 87bc044bb666da17a632707ef8c86a1cf99f89f1
parent 05273ed092d5263f500d253c7603a7e3c62b4872
Author: Michael Neuper <73108749+michaelneuper@users.noreply.github.com>
Date: Sun, 12 Feb 2023 22:16:34 +0200
Add comments to isValidEmail method
Diffstat:
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java
@@ -40,17 +40,26 @@ public class LoginController {
* @return true if the email is a valid email format, false otherwise
*/
private boolean isValidEmail(String email) {
+ // Check if email is null
+ if (email == null) {
+ JOptionPane.showMessageDialog(null, "Please enter an email");
+ }
+
+ // Define regular expression pattern for valid email addresses
String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." +
"[a-zA-Z0-9_+&*-]+)*@" +
- "(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; // regular expression representing a valid email
+ "(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
Pattern pattern = Pattern.compile(emailRegex);
-
+
+ // Check if email matches the pattern
boolean isValid = pattern.matcher(email).matches();
-
+
+ // If email is not valid, show error message
if (!isValid) {
JOptionPane.showMessageDialog(null, "Please enter a valid email");
}
-
+
+ // Return whether email is valid
return isValid;
}