Initial commit: suixinkan_ios UIKit rewrite project.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-26 14:33:31 +08:00
commit 9edf993432
297 changed files with 47151 additions and 0 deletions

View File

@ -0,0 +1,74 @@
//
// AppFormValidator.swift
// suixinkan
//
// Created by Codex on 2026/6/25.
//
import Foundation
///
enum AppFormValidator {
///
static func normalizedPhoneNumber(_ value: String) -> String {
value.filter { !$0.isWhitespace }
}
/// 11
static func isValidMainlandPhoneNumber(_ value: String) -> Bool {
let phone = normalizedPhoneNumber(value)
guard phone.count == 11, phone.first == "1" else { return false }
return phone.allSatisfy(\.isNumber)
}
///
static func rangedInteger(_ text: String, name: String, range: ClosedRange<Int>) throws -> Int {
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty, let value = Int(trimmed) else {
throw APIError.networkFailed("\(name)格式不正确")
}
guard range.contains(value) else {
throw APIError.networkFailed("\(name)须在 \(range.lowerBound)\(range.upperBound)")
}
return value
}
///
static func validateQueueNoticeThresholds(first: Int, second: Int) throws {
guard second <= first else {
throw APIError.networkFailed("第二次通知阈值不能大于第一次通知阈值")
}
}
///
static func sanitizedMoneyInput(_ input: String, maxDecimalPlaces: Int = 2) -> String {
var result = ""
var hasDot = false
var decimalCount = 0
for char in input {
if char.isNumber {
if hasDot {
guard decimalCount < maxDecimalPlaces else { continue }
decimalCount += 1
}
result.append(char)
} else if char == ".", !hasDot {
hasDot = true
result.append(char)
}
}
if result.hasPrefix(".") {
result = "0" + result
}
return result
}
///
static func normalizedMoneyForSubmit(_ input: String) -> String {
let sanitized = sanitizedMoneyInput(input, maxDecimalPlaces: 2)
guard !sanitized.isEmpty, sanitized != "." else { return "" }
return sanitized
}
}