Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions entourage/Tools/CountryCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ public let defaultCountryCode = CountryCode(country: "France", code: "+33", flag
public let allCountryCodes: [CountryCode] = [
CountryCode(country: "France", code: "+33", flag: "🇫🇷"),
CountryCode(country: "Belgique", code: "+32", flag: "🇧🇪"),
CountryCode(country: "Guadeloupe", code: "+590", flag: "🇫🇷"),
CountryCode(country: "Martinique", code: "+596", flag: "🇫🇷"),
CountryCode(country: "Guyane", code: "+594", flag: "🇫🇷"),
CountryCode(country: "La Réunion", code: "+262", flag: "🇫🇷"),
CountryCode(country: "Mayotte", code: "+262", flag: "🇫🇷"),
CountryCode(country: "Polynésie", code: "+689", flag: "🇫🇷"),
CountryCode(country: "Nouvelle-Calédonie", code: "+687", flag: "🇫🇷"),
CountryCode(country: "Saint-Martin / St-Barth", code: "+590", flag: "🇫🇷"),
]
18 changes: 16 additions & 2 deletions entourage/Tools/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,33 @@ import UIKit

static func validatePhoneFormat(countryCode:String?, phone:String) -> String {
var correctPhone = phone.trimmingCharacters(in: .whitespaces)
var appliedCountryCode = countryCode

// Auto-detect DOM-TOM prefixes if France is selected or no country code is provided
if appliedCountryCode == "+33" || appliedCountryCode == nil {
if correctPhone.hasPrefix("0690") || correctPhone.hasPrefix("0691") {
appliedCountryCode = "+590"
} else if correctPhone.hasPrefix("0696") || correctPhone.hasPrefix("0697") {
appliedCountryCode = "+596"
} else if correctPhone.hasPrefix("0694") {
appliedCountryCode = "+594"
} else if correctPhone.hasPrefix("0692") || correctPhone.hasPrefix("0693") || correctPhone.hasPrefix("0639") {
appliedCountryCode = "+262"
}
}

if correctPhone.starts(with: "0") {
//correctPhone.remove(at: .init(encodedOffset: 0))
correctPhone.remove(at: .init(utf16Offset: 0, in: correctPhone))
if let _code = countryCode {
if let _code = appliedCountryCode {
correctPhone = _code + correctPhone
}
else {
correctPhone = "+33\(correctPhone)"
}
}
else if !correctPhone.starts(with: "+") {
if let _code = countryCode {
if let _code = appliedCountryCode {
correctPhone = _code + correctPhone
}
}
Expand Down