|
|
|
|
@ -225,6 +225,23 @@ public extension String { |
|
|
|
|
firstMatch(of: RegexStatic.phoneNumber) != nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func normalize(_ phone: String) -> String { |
|
|
|
|
var normalized = phone.trimmingCharacters(in: .whitespacesAndNewlines) |
|
|
|
|
// Remove all non-digit characters |
|
|
|
|
normalized = normalized.components(separatedBy: CharacterSet.decimalDigits.inverted).joined() |
|
|
|
|
// Remove leading country code for France (33) if present |
|
|
|
|
if normalized.hasPrefix("33") { |
|
|
|
|
normalized = "0" + normalized.dropFirst(2) |
|
|
|
|
} else if normalized.hasPrefix("0033") { |
|
|
|
|
normalized = "0" + normalized.dropFirst(4) |
|
|
|
|
} |
|
|
|
|
return normalized |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isSamePhoneNumber(as other: String) -> Bool { |
|
|
|
|
return normalize(self) == normalize(other) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func cleanSearchText() -> String { |
|
|
|
|
// Create a character set of all punctuation except slashes and hyphens |
|
|
|
|
var punctuationToRemove = CharacterSet.punctuationCharacters |
|
|
|
|
@ -312,3 +329,4 @@ public extension String { |
|
|
|
|
return self // Return the original string if parsing fails |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|