Validate email and phone number in swift

1

How can I validate in 2 textfield if the data you are entering are: An email and a phone number ??

I have this code:

campoMovil.keyboardType = .numberPad
campoEmail.keyboardType = .emailAddress
    
asked by 25.11.2016 в 08:26
source

1 answer

2

When you finish collecting the values you pass this filter:

class func isOnlyNumbers(string: String) -> Bool {
    return NSPredicate(format: "SELF MATCHES %@", "\d{10}").evaluateWithObject(string)
}

class func isValidEmail(string: String) -> Bool {
    let emailReg = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}"
    let emailTest = NSPredicate(format:"SELF MATCHES %@", emailReg)
    return emailTest.evaluateWithObject(string)
}
    
answered by 25.11.2016 / 08:49
source