I have a password field, and the way I use validation looks something like this:
-(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;
}
The way I verify the password confirmation is:
-(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;
}
The problem I am facing is whenever I print the exact value for both fields, for example:
"password": "Test" "ConfirmPassword": "test"
works fine.
Now, when I replace one key like "confirmPassword": "tes", my verification methods do not work, because it does not set a value for the key.
How can I deal with this problem?
source
share