MojtabaHs / iPhoneNumberField

Elegant SwiftUI phone number textField.
MIT License
542 stars 88 forks source link

Phone number formatted to actual number! #99

Closed AbdelrahmanShehab closed 9 months ago

AbdelrahmanShehab commented 9 months ago

how can I take the whole number, i.e: "+201203526716" without no spacing like this "12 03526716"

MojtabaHs commented 9 months ago

You can import PhoneNumberKit and parse the number; then you can do any manipulation you need to like:

@State var number: String = "+201203526716"
var nationalNumber: String {
    (try? PhoneNumberKit().parse(number).adjustedNationalNumber()) ?? ""
}

Of course, you should handle the throwing and use @State or any other needs 🙌🏻