现在的位置: 首页 > 综合 > 正文

正则汇总 个人汇总 不断更新中

2018年05月12日 ⁄ 综合 ⁄ 共 1056字 ⁄ 字号 评论关闭

/*手机号码验证 MODIFIED BY HELENSONG*/
+ (BOOL) isValidateMobile:(NSString *)mobile
{
    //手机号以13, 15,18开头,八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    //    //NSLog(@"phoneTest is %@",phoneTest);
    return [phoneTest evaluateWithObject:mobile];
}

//匹配Email地址的正则表达式:^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$
//
+ (BOOL)isRightEmail:(NSString *)str
{
    NSString *phoneRegex = @"^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    //    //NSLog(@"phoneTest is %@",phoneTest);
    return [phoneTest evaluateWithObject:str];
}

//17位 最后4位必须是数字
- (BOOL)isRightCarUniqueNumber:(NSString *)str
{
    NSString *phoneRegex = @"^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    //    //NSLog(@"phoneTest is %@",phoneTest);
    return [phoneTest evaluateWithObject:str];
}

抱歉!评论已关闭.