feat(gift): 연락처 입력 규칙을 추가한다

This commit is contained in:
Yu Sung
2026-10-08 12:32:45 +09:00
parent a5398b7658
commit 0383115ca7
3 changed files with 128 additions and 0 deletions
@@ -0,0 +1,33 @@
enum GiftContactInputRule {
case name
case phoneNumber
func acceptsEditing(_ text: String) -> Bool {
switch self {
case .name:
return text.count <= 12 && text.unicodeScalars.allSatisfy { scalar in
switch scalar.value {
case 0x41...0x5A, 0x61...0x7A,
0x1100...0x11FF, 0x3130...0x318F,
0xA960...0xA97F, 0xAC00...0xD7A3, 0xD7B0...0xD7FF:
return true
default:
return false
}
}
case .phoneNumber:
return text.count <= 11 && text.unicodeScalars.allSatisfy {
(0x30...0x39).contains($0.value)
}
}
}
func acceptsSubmission(_ text: String) -> Bool {
switch self {
case .name:
return !text.isEmpty && acceptsEditing(text)
case .phoneNumber:
return text.count == 11 && text.hasPrefix("010") && acceptsEditing(text)
}
}
}