// // SDLUtil.swift // punchnet // // Created by 安礼成 on 2026/3/9. // struct SDLUtil { enum ContactType { case phone case email case invalid } 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,}$/ if trimmed.wholeMatch(of: phoneRegex) != nil { return .phone } else if trimmed.wholeMatch(of: emailRegex) != nil { return .email } else { return .invalid } } }