0

我正在使用的应用程序上有一个注册表单。您输入您的电子邮件,然后输入您想要的密码和验证密码。它需要检查两个密码字段是否passwordFieldOnepasswordFieldTwo和不相等。他们需要检查它们是否不相等,我的错误过程才能正常工作。这是我尝试过的一些事情。

    if(passwordFieldOne != passwordFieldTwo){
        //do whatever
    }

-

    if(passwordFieldOne.text != passwordFieldTwo.text){
        //do whatever
    }

-

    if((passwordFieldOne.text == passwordFieldTwo.text) == False){
        //do whatever
    }

PS。请不要回复告诉我我可以检查它们是否相等,或者检查它们是否相等然后再说。谢谢你的帮助。

4

3 回答 3

5
-(BOOL)isPasswordMatch:(NSString *)pwd withConfirmPwd:(NSString *)cnfPwd {
//asume pwd and cnfPwd has not whitespace
    if([pwd length]>0 && [cnfPwd length]>0){
        if([pwd isEqualToString:cnfPwd]){
           NSLog(@"Hurray! Password matches ");
           return TRUE;
        }else{
           NSLog(@"Oops! Password does not matches");
           return FALSE;
        }
    }else{
         NSLog(@"Password field can not be empty ");
         return FALSE;
    }
return FALSE;
}
于 2011-08-12T21:53:00.577 回答
5

比较字符串的使用 isEqualToString:方法:

if([passwordFieldOne.text isEqualToString:passwordFieldTwo.text]) {
    // passwords are equal
}
于 2011-08-12T21:46:44.963 回答
0

您在比较 _passwordText 和 _confirmPasswordText 的代码下方

  if ([_passwordText.text isEqual:_confirmPasswordText.text])
        {
            NSLog(@"Password =%@   , ConfirmPassword = %@ is equal ",_passwordText.text,_confirmPasswordText.text);
        }
        else {
            UIAlertController *alertConnection= [UIAlertController
                                                 alertControllerWithTitle:@""
                                                 message:@"Password do not match! "
                                                 preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction* okBtnConnection= [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                                   handler:^(UIAlertAction * action){
                                                                       [self.view endEditing:YES];
                                                                   }
                                             ];
            [alertConnection addAction:okBtnConnection];
            [[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor redColor]];
            [self presentViewController:alertConnection animated:YES completion:nil];
于 2017-05-13T11:54:13.630 回答