检查密码字段和验证密码字段是否不相等?

发布于 2024-11-29 06:13:27 字数 576 浏览 0 评论 0原文

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

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

-

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

-

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

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

I have a registration form on an app im working on. You enter your email then your desired password and a verify password. It needs to check if the two password fieldspasswordFieldOne and passwordFieldTwo and not equal. They need to check if they are not equal for my error process to work correctly. Here are some things I tried.

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

-

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

-

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

PS. Please dont respond telling me I can just check if they are equal, or check if they are equal and then say else. Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倚栏听风 2024-12-06 06:13:27
-(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;
}
-(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;
}
街角迷惘 2024-12-06 06:13:27

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

if([passwordFieldOne.text isEqualToString:passwordFieldTwo.text]) {
    // passwords are equal
}

Use isEqualToString: method for comparing strings:

if([passwordFieldOne.text isEqualToString:passwordFieldTwo.text]) {
    // passwords are equal
}
御弟哥哥 2024-12-06 06:13:27

下面是比较 _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];

You below code of comparing _passwordText and _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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文