手机号码正则验证(试用版)

前端之家收集整理的这篇文章主要介绍了手机号码正则验证(试用版)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//手机号码正则验证
- (BOOL)checkTel:(NSString *)str
{
    if ([str length] == 0) {
        [self showAlertView:@"请输入手机号码"];
        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) {
        [self showAlertView:@"手机号码输入有误"];
        return NO;
    }else {
        [self showAlertView:@"修改成功"];
    }
    return YES;
}

- (void)showAlertView:(NSString *)string {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:string delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil,nil];
    [alertView show];
}
原文链接:/regex/360753.html

猜你在找的正则表达式相关文章