punchnet-macos/punchnet/Core/SDLUtil.swift
2026-03-09 22:04:34 +08:00

31 lines
797 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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
}
}
}