Email & Phone Validation in Swift

后端 未结 21 1841
长发绾君心
长发绾君心 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:52

    The following code works in xcode 6.3 beta

    func isValidEmail(testStr:String) -> Bool {
    
       let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
       let range = testStr.rangeOfString(emailRegEx, options:.RegularExpressionSearch)
       let result = range != nil ? true : false
       return result
    
    }
    

    how to use it:

    Ex.

    if isValidEmail(email.text) == false{
    //your code here
    }
    

提交回复
热议问题