From fd87c244b90c0c84b9837918073ac31d65489764 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Thu, 19 Mar 2026 20:13:50 +0800 Subject: [PATCH] fix register flow --- punchnet/Core/SDLUtil.swift | 12 +++++++++++- punchnet/Views/Register/RegisterView.swift | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/punchnet/Core/SDLUtil.swift b/punchnet/Core/SDLUtil.swift index ac0988b..0390996 100644 --- a/punchnet/Core/SDLUtil.swift +++ b/punchnet/Core/SDLUtil.swift @@ -34,14 +34,24 @@ struct SDLUtil { } return digest.map { String(format: "%02x", $0) }.joined() + } + static func isValidIdentifyContact(_ input: String) -> Bool { + switch identifyContact(input) { + case .email, .phone: + true + default: + false + } + } + static func identifyContact(_ input: String) -> ContactType { let trimmed = input.trimmingCharacters(in: .whitespacesAndNewlines) // 手机号正则(中国手机号为例,以 1 开头,11 位数字) let phoneRegex = /^1[3-9][0-9]{9}$/ // 邮箱正则 - let emailRegex = /^[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$/ + let emailRegex = /^[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,64}$/ if trimmed.wholeMatch(of: phoneRegex) != nil { return .phone } else if trimmed.wholeMatch(of: emailRegex) != nil { diff --git a/punchnet/Views/Register/RegisterView.swift b/punchnet/Views/Register/RegisterView.swift index a6dbd19..0ed43fe 100644 --- a/punchnet/Views/Register/RegisterView.swift +++ b/punchnet/Views/Register/RegisterView.swift @@ -102,7 +102,7 @@ struct RegisterRequestVerifyCodeView: View { .buttonStyle(.borderedProminent) .controlSize(.large) .frame(width: 280) - .disabled(username.isEmpty || isProcessing) + .disabled(!SDLUtil.isValidIdentifyContact(username) || isProcessing) Spacer() }