iOS 手机号格式验证

    

   //---验证手机号的UIBtutton--

    self.submitBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];

    self.submitBtn.frame = CGRectMake(0, self.undoView.frame.origin.y+self.undoView.frame.size.height, self.view.frame.size.width, 35);

    self.submitBtn.backgroundColor = [UIColor colorWithHexString:@"47a5d6"];

    //self.submitBtn.alpha = 0.5;

    [self.submitBtn setTitle:@"发送" forState:(UIControlStateNormal)];

    [self.submitBtn addTarget:self action:@selector(didBtnAction) forControlEvents:(ValidationEmailFormat)];

//邮箱地址

    self.emailFT = [[UITextField alloc] initWithFrame:CGRectMake(30, lineView.frame.origin.y+lineView.frame.size.height + 15, self.view.frame.size.width-60, 40)];

    self.emailFT.backgroundColor = [UIColor colorWithHexString:@"f8f8f8"];

    self.emailFT.placeholder = @"您的手机号!";

    self.emailFT.font = [UIFont systemFontOfSize:17.0];

    self.emailFT.clearsOnBeginEditing = YES;

    self.emailFT.textAlignment = NSTextAlignmentCenter;

    [self.view addSubview:self.emailFT];



//[Dubai]验证手机号是否正确

- (void)ValidationEmailFormat

{

    

    NSString *mobileRegex = @"^((13[0-9])|(147)|(170)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";

    NSPredicate *mobileTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileRegex];

    BOOL n = [mobileTest evaluateWithObject:self.emailFT.text];

    if (n == NO) {

        [AlertVC showWithMessage:@"手机号格式不正确!"];

         self.navigationItem.rightBarButtonItem.enabled = YES;

        [self removeLoadingView];

        [self.timerTT invalidate];

        

    }else{

        [self.timerTT fire];

        //[self removeLoadingView];

        [self closeVC];

        self.navigationItem.rightBarButtonItem.enabled = YES;

    

    }

}


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。