I have used CNContactPickerViewController to enable user to pick a contact from their contact list stored on the phone. I use the contact name and number using CNContactPicker delegate methods. Code as below
func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
// You can fetch selected name and number in the following way
// user name
let userName: String = "\(contact.givenName) \(contact.familyName)"
// user phone number
let userPhoneNumbers:[CNLabeledValue<CNPhoneNumber>] = contact.phoneNumbers
let firstPhoneNumber:CNPhoneNumber = userPhoneNumbers[0].value
// user phone number string
let primaryPhoneNumberStr:String = firstPhoneNumber.stringValue
// print(primaryPhoneNumberStr)
textfieldName.text = userName
textfieldContactNo.text = primaryPhoneNumberStr
}
I would like to apply validations following validations to it -
Selected no is a mobile phone or landline number.
Check if the number has a country code.
Can someone please help me with the above validations.