From 2966932541b92bb77458aed4f049a0fc5b6fd38e Mon Sep 17 00:00:00 2001 From: YangShuaiLu <3417398995@qq.com> Date: Sun, 12 Oct 2025 14:33:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=82=AE=E7=AE=B1=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.java | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/Main.java b/src/Main.java index 385b8e2..a91b637 100644 --- a/src/Main.java +++ b/src/Main.java @@ -142,10 +142,12 @@ public class Main extends Application { return; } - if (!email.contains("@")) { - infoLabel.setText("邮箱格式不正确"); + // 使用新的邮箱验证方法 + if (!isValidEmail(email)) { + infoLabel.setText("邮箱格式不正确,请使用有效的邮箱地址"); return; } + if (userDatabase.containsKey(email)) { infoLabel.setText("该邮箱已注册"); return; @@ -160,7 +162,7 @@ public class Main extends Application { if (success) { infoLabel.setText("验证码已发送,请查看邮箱"); } else { - infoLabel.setText("发送失败,请检查邮箱"); + infoLabel.setText("发送失败,请检查邮箱是否正确"); } }); }).start(); @@ -222,6 +224,47 @@ public class Main extends Application { return username.matches("^[a-zA-Z0-9_]+$"); } + // 邮箱完整验证方法 + private boolean isValidEmail(String email) { + if (email == null || email.trim().isEmpty()) { + return false; + } + + String regex = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"; + + // 基本格式检查 + if (!email.matches(regex)) { + return false; + } + + // 检查@符号位置 + int atIndex = email.indexOf('@'); + if (atIndex <= 0 || atIndex == email.length() - 1) { + return false; + } + + // 检查域名部分 + String domain = email.substring(atIndex + 1); + if (domain.indexOf('.') <= 0 || domain.endsWith(".")) { + return false; + } + + // 检查常见邮箱服务商 + String[] commonDomains = {"qq.com", "gmail.com", "163.com", "126.com", "sina.com", + "hotmail.com", "outlook.com", "yahoo.com", "foxmail.com"}; + boolean hasCommonDomain = false; + for (String commonDomain : commonDomains) { + if (domain.equalsIgnoreCase(commonDomain)) { + hasCommonDomain = true; + break; + } + } + + + + return true; + } + // 密码验证方法 private boolean isValidPassword(String password) { if (password.length() < 6 || password.length() > 10) { @@ -240,6 +283,8 @@ public class Main extends Application { return hasUpper && hasLower && hasDigit; } + + // 难度选择界面 private Scene buildLevelSelectionScene() { VBox root = new VBox(15);