-2

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.

Lisa
  • 13
  • 3
  • Welcome Lisa. Two questions: 1) what have you tried so far? 2) what about users from different countries that may have different conditions? – Christophe Jul 19 '21 at 08:37

1 Answers1

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