I have a simple TextField for telephone input, and want to format it each time it being changed.
I'm using PhoneNumberKit and it works fine, but i do not understand how to call formatting func after the value in textField have changed.
Telephone Formatting function.
import SwiftUI
import PhoneNumberKit
import Combine
func formatTelephone(telephone : String) -> String
{
do {
let phoneNumber = PartialFormatter().formatPartial(telephone)
print(phoneNumber)
return phoneNumber
}
catch {
print("Generic parser error")
}
}
It does something like this:
formatTelephone("79152140700") -> "7 (915) 214 08-00"
formatTelephone("791521") -> "7 (915) 21"
and i have a TextField like that
TextField("915 214 07 00" , text: $telephoneManager.telephone)
After each input of a digit the whole textfield label needs to be formatted by a func and show user's input in a better way.