判断一个字符串是不是手机号

时间:2014-12-15 18:55:37   收藏:0   阅读:349

//判断手机号是否正确

- (BOOL)checkTel:(NSString *)str

 

{

    if ([str length] == 0) {

        

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"手机号不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        

        [alert show];

        return NO;

    }

    

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

    

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

    

    BOOL isMatch = [pred evaluateWithObject:str];

    

    if (!isMatch) {

        

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的手机号码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        

        [alert show];

        return NO;

    }

    return YES;

}

 

原文:http://www.cnblogs.com/zhangshan/p/4165441.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!