Validate phone number ios

前端 未结 9 1755
温柔的废话
温柔的废话 2020-12-10 00:42

I need to validate an international phone number.

I know its difficult to validate an international phone number, so I\'m going to keep it simple:

+

9条回答
  •  温柔的废话
    2020-12-10 01:45

    In swift 4 -

    func ValidateMobileNumber(txtFeid : UITextField, strChk : String, range: NSRange) -> Bool {
    
        if txtFeid.text!.count >= 10 {
            return false
        } 
    
        let formatePre = "^((\\+)|(00))[0-9]{6,14}$"
        let resultPredicate : NSPredicate = NSPredicate(format: "SELF MATCHES %@",formatePre)
        return resultPredicate.evaluate(with: strChk)
    }
    

提交回复
热议问题