fixed a bug

This commit is contained in:
2026-09-09 12:31:05 +08:00
parent fb64343a9f
commit 9d956183c7
5 changed files with 185 additions and 9 deletions

View File

@@ -234,7 +234,7 @@ struct RegisterView: View {
.overlay(RoundedRectangle(cornerRadius: 8).stroke(Theme.border, lineWidth: 1))
fieldLabel("手机号")
TextField("选填", text: $phone)
TextField("请输入 11 位手机号", text: $phone)
.textFieldStyle(.plain)
.keyboardType(.phonePad)
.padding(12)
@@ -292,13 +292,18 @@ struct RegisterView: View {
guard username.count >= 3 else { statusText = "用户名至少 3 个字符"; return }
guard password.count >= 8 else { statusText = "密码至少 8 位"; return }
guard !nickname.isEmpty else { statusText = "请填写姓名"; return }
let cleanedPhone = phone.trimmingCharacters(in: .whitespaces)
guard cleanedPhone.range(of: "^1[3-9]\\d{9}$", options: .regularExpression) != nil else {
statusText = "请输入有效的 11 位手机号"
return
}
isLoading = true
statusText = "注册中..."
defer { isLoading = false }
do {
let session = try await AuthAPI.register(
username: username, password: password, nickname: nickname, phone: phone
username: username, password: password, nickname: nickname, phone: cleanedPhone
)
auth.saveSession(session)
dismiss()