iOS正则表达式笔记

xiaoxiao2021-02-28  8

#pragma mark --判断手机号合法性

+ (BOOL)checkPhone:(NSString *)phoneNumber

{

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

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

    BOOL isMatch = [pred evaluateWithObject:phoneNumber];

    if (!isMatch)

    {

        return NO;

    }

    return YES;

    

}

转载请注明原文地址: https://www.6miu.com/read-850402.html

最新回复(0)