iOS----简单的注册信息判断(根据需要修改)

简单的判断用户名,密码,确认密码,手机号码,验证码为空,输入信息含空格,密码不一致

#pragma mark--判断输入内容
-(BOOL)isNULL{
    
    //设置判断值
    BOOL result = YES;
    //警示框内容
    NSString* msg = @"";
    //判断内容
    if (self.register_userNameTF.text.length == 0) {
        //为空时  判断值为NO
        result = NO;
        msg = @"用户名为空";
    }else  if (self.register_userPwdTF.text.length == 0) {
        //为空时  判断值为NO
        result = NO;
        msg = @"密码为空";
    }else if (self.register_surePwdTF.text.length == 0) {
        //为空时  判断值为NO
        result = NO;
        msg = @"确认密码为空";
    }else if (self.register_phoneNumberTF.text.length == 0) {
        //为空时  判断值为NO
        result = NO;
        msg = @"手机号码为空";
    }else if (self.register_verificationCodeTF.text.length == 0) {
        //为空时  判断值为NO
        result = NO;
        msg = @"验证码为空";
    }else if ([self.register_userNameTF.text containsString:@" "] || [self.register_userPwdTF.text containsString:@" "] || [self.register_surePwdTF.text containsString:@" "] || [self.register_phoneNumberTF.text containsString:@" "] || [self.register_verificationCodeTF.text containsString:@" "] ) {
        //输入带有空格时  判断值为NO
        result = NO;
        msg = @"输入含有空格为空";
    }else if (![self.register_userPwdTF.text isEqualToString:self.register_surePwdTF.text]) {
        //密码与确认密码不一致 判断值为NO
        result = NO;
        msg = @"密码不一致";
    }
    
    //判断值
    if (result) {
        //若为YES,直接返回
        return result;
    }else{
        //调用弹出方法
        [self alertWithMsg:msg];
        return result;
    }
}

1.以警示框形式弹出

#pragma mark--警示框
-(void) alertWithMsg:(NSString*)msg{
    
    //初始化AlertController11
    UIAlertController* alertC = [UIAlertController alertControllerWithTitle:@"友情提示" message:msg preferredStyle:(UIAlertControllerStyleAlert)];
    //设置确认按钮组件方法
    UIAlertAction* alertAction = [UIAlertAction actionWithTitle:@"确认" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action){
        
        NSLog(@"点击确认");
    }];
    //添加确认按钮组件
    [alertC addAction:alertAction];
    //模态弹出警示框
    [self presentViewController:alertC animated:YES completion:nil];
    
}

2.以提醒框形式弹出

导入
#import "MBProgressHUD.h"//提示框
属性
@property (nonatomic,strong) MBProgressHUD* toastView;//弹出提示
懒加载
#pragma mark--懒加载
-(MBProgressHUD*) toastView{
    
    if (!_toastView) {
        _toastView = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        _toastView.minShowTime = 2;
        [_toastView setMode:MBProgressHUDModeText];
        _toastView.contentColor = [UIColor grayColor];
        _toastView.bezelView.backgroundColor = [UIColor blackColor];
    }
    return _toastView;
}

提醒框方法
#pragma mark--提示框
-(void) alertWithMsg:(NSString*)msg{
    
    self.toastView.label.text =msg;
    [self.toastView hideAnimated:YES];
    //隐藏掉之后回执行的block
    UserInfoVC* vc_self = self;
    self.toastView.completionBlock = ^{
        
        [vc_self.toastView removeFromSuperview];
        vc_self.toastView = nil;
    };
    
}

你可能感兴趣的:(iOS----简单的注册信息判断(根据需要修改))