I want to get my cell phone number and check if it fits the conditions. The condition I want is ***********. Of course * should be expressed as a number.
Asked
Active
Viewed 72 times
1 Answers
1
You can solve this by using a regular expression.
func isValidPhone(phone: String?) -> Bool {
guard phone != nil else { return false }
let phoneRegEx = "[0-9]{11}"
let pred = NSPredicate(format:"SELF MATCHES %@", phoneRegEx)
return pred.evaluate(with: phone)
}
If you add the string you want to this function, confirm that it meets the requirements.

Hailey
- 302
- 1
- 7