gpt4 book ai didi

ios - 在 IOS 应用程序中验证

转载 作者:行者123 更新时间:2023-11-28 19:30:54 28 4
gpt4 key购买 nike

我知道这是一个简单的问题,但我已经尝试了很多次代码检查验证,但它不起作用。当我单击注册按钮时,它会将我带到下一页而不是验证我的表单。我的代码是

- (IBAction)Register:(id)sender {
if ([self.name.text isEqualToString:@""]){
NSString *message = @"Name";

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Your Name"
message:message
preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];

int duration = 1; // duration in seconds

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});

} else if ([self.email.text isEqualToString:@""]){
NSString *message = @"Email";

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Your Email Address"
message:message
preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];

int duration = 1; // duration in seconds

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});

}else{

NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
//Valid email address

if ([emailTest evaluateWithObject:_email.text] == YES)
{
// NSLog(@"Correct Email");
}
else
{
NSString *message = @"Invalid Email";

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Email Format Incorrect"
message:message
preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];

int duration = 1; // duration in seconds

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});

}

if ([_code.titleLabel.text isEqualToString:@"Code"]) {
NSString *message = @"Select Country Code";

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
message:message
preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];

int duration = 1; // duration in seconds

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});

}


if ([self.mobileCode.text isEqualToString:@""]) {
NSString *message = @"Enter Mobile Code";

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
message:message
preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];

int duration = 1; // duration in seconds

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});

}

if ([self.number1.text isEqualToString:@""]) {
NSString *message = @"Enter Your Number";

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
message:message
preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];

int duration = 1; // duration in seconds

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});

}





}
[self Account];



}

最佳答案

验证您的 TextFiled 的最佳方法是

创建验证方法

-(BOOL)validation
{

if (self.name.text.length==0){
// Show alert enter Name
return NO;

}

if ([self.email.text.length==0){
// Show alert enter Email
return NO;

}

if ([_code.titleLabel.text.length==0){
// Show alert Select Country
return NO;

}

// Similarly Create method to validate your email
if (![self validateEmailString:self.email.text]){
// Show alert invalid email
return NO;

}

// and so on check your validation

//Finally retrun YES , validation Over
return YES;
}

使用

if ([self validation])
{
// validation over than call your API
[self Account];
}

关于ios - 在 IOS 应用程序中验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44941236/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com