Remove the unwanted charaters in a phone Number iOS swift

Solution:

You can get the phone number from the user in textfield and format it as a valid phone number using the below expression.


 let ValidNo = number.value.stringValue.replacingOccurrences(of: "[^0-9+]", with: "", options: NSString.CompareOptions.regularExpression, range:nil)



The above expression will truncate the special characters in the phone Number.So you can save the phone number directly to your database.

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift