您好我是Swift开发的新手。我正在开发用于用户输入字段验证的代码。我已导入Validator和 SwiftValidator
库。我无法摆脱这个错误。我也遵循更新的语法,但错误仍然存在。
以下是代码:
func addFieldValidation() {
var emailRules = ValidationRuleSet<String>()
emailRules.add(rule: ValidationRulePattern(pattern: .EmailAddress, error: ValidationError(textField:emailTextField, error: "Enter valid email address"))) //****<---Getting error here******
emailTextField.validationRules=emailRules;
emailTextField.validateOnInputChange(enabled: true);
emailTextField.validationHandler = { result in
switch result {
case .valid:
self.enableSignUp(true)
case .invalid(let failureErrors):
let messages = failureErrors.map { $0.message }//****<---Getting error here as "Value of type 'Error' has no member 'message' "******
print(messages)
self.enableSignUp(false)
}
}
}
提前致谢。
答案 0 :(得分:0)
我有不同的电子邮件验证方式
// email validation method
func isValidEmail(emailAddress:String) -> Bool {
// print("validate calendar: \(testStr)")
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailTest.evaluate(with: emailAddress)
}