func isValidEmail(testStr:String) -> Bool {
// println("validate calendar: \(testStr)")
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailTest.evaluateWithObject(testStr)
}
有谁知道如何在Swift中验证电子邮件地址?我找到了这段代码:
答案 0 :(得分:0)
假设txtEmail是您的UITextField:
var isValid = isValidEmail(txtEmail.text)
if isValid {
// Do some things when email is valid
}
else {
// Show error to user
}