码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 手机号格式验证

时间:2015-04-27 15:23:12      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:学习

    

   //---验证手机号的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;

    

    }

}


iOS 手机号格式验证

标签:学习

原文地址:http://blog.csdn.net/zhaoguodongios/article/details/45308961

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!