无法使用参数错误调用“isValidEmail”

时间:2015-05-25 08:16:07

标签: swift email-validation

我是新手,面对一个验证电子邮件的小问题

//Login API CALL
@IBAction func loginButton(sender: AnyObject) {
    var userModel = UserModel();
    var data_info: [String:AnyObject] =
    [
        "udid" : "",
        "email" : "someemail",
        "password" : "soempass"
    ];
    var checkInput = UserModel.isValidEmail(data_info["email"]); //Error here
    if (checkInput) {
      var isTrue = UserModel.doLogin(data_info:Dictionary<String,AnyObject>.self);
    }
}

//Validate Email
func isValidEmail(testStr:AnyObject) -> Bool {
    println("validate emilId: \(testStr)")
    let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
    var emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
    var result = emailTest.evaluateWithObject(testStr)
    return result
}

有任何类型问题吗?我应该将AnyObject更改为String吗? UserModel是一个验证电子邮件地址的外部类 谢谢你提前!

1 个答案:

答案 0 :(得分:1)

尝试使用小&#34; u&#34;,这是实例,用资本&#34; U&#34;它是班级

userModel.isValidEmail(data_info["email"]);