Email & Phone Validation in Swift

后端 未结 21 1833
长发绾君心
长发绾君心 2020-12-07 12:02

i am using the following code for phone number validation. But i am getting the following error. I cant able to proceed further. Help us to take it forward.

         


        
21条回答
  •  情书的邮戳
    2020-12-07 12:39

    Using Swift 3

     func validate(value: String) -> Bool {
        let PHONE_REGEX = "^\\d{3}-\\d{3}-\\d{4}$"
        let phoneTest = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
        let result =  phoneTest.evaluate(with: value)
        return result
    }
    

提交回复
热议问题