如何使用validateValue验证确认密码字段

时间:2015-07-10 06:35:47

标签: validation ios7 ios8 uitextfield

我有一个密码字段,我使用验证的方式是这样的:

-(BOOL)validatePassword:(id *)ioValue error:(NSError **)outError{
    if (*ioValue == nil) {
        if (outError != NULL) {
            NSString *errorString = NSLocalizedString(
                                                      @"Password must not be empty",
                                                      @"validation: Person, Password empty error");
            NSDictionary *userInfoDict = @{ NSLocalizedDescriptionKey : errorString };
            *outError = [[NSError alloc] initWithDomain:PERSON_ERROR_DOMAIN
                                                   code:PERSON_INVALID_PASSWORD_CODE
                                               userInfo:userInfoDict];
        }
        return NO;
    }
    return YES;
}

我验证确认密码字段的方式是:

-(BOOL)validateConfirmPassword:(id *)ioValue error:(NSError **)outError{
    if ((*ioValue == nil) ||am (![self.password isEqualToString:*ioValue])) {
        if (outError != NULL) {
            NSString *errorString = NSLocalizedString(
                                                      @"Your passwords must match.",
                                                      @"validation: Person, Passwords must match. error");
            NSDictionary *userInfoDict = @{ NSLocalizedDescriptionKey : errorString };
            *outError = [[NSError alloc] initWithDomain:PERSON_ERROR_DOMAIN
                                                   code:PERSON_INVALID_CONFIRM_PASSWORD_CODE
                                               userInfo:userInfoDict];
        }
        return NO;
    }
    return YES;
}

我面临的问题是,每当我输入两个字段的确切值时,如:

"密码":"测试" " confirmPassword":"测试"

工作正常。

现在,当我更换一个密钥时,例如:&#34; confirmPassword&#34;:&#34; tes&#34; ,我的验证方法失败,因为它没有为密钥设置值。< / p>

我如何处理这个问题?

0 个答案:

没有答案