正则匹配,邮箱、电话号码合法性

来源:互联网 发布:非关系型数据库的特点 编辑:程序博客网 时间:2024/04/29 12:51
#pragma mark  拨打号码+(UIWebView *)callPhoneView:(NSString *)phone{        NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]];    UIWebView *phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];    [phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];    return phoneCallWebView;}#pragma mark  邮箱合法验证+(BOOL)isValidateEmail:(NSString *)email{    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];    BOOL bo= [emailTest evaluateWithObject:email];    return bo;}#pragma mark  手机合法验证+(BOOL) isValidateMobile:(NSString *)mobile{    //手机号以13, 15,18开头,八个 \d 数字字符    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];    return [phoneTest evaluateWithObject:mobile];}

0 0