iOS开发判断手机号格式

// 判断手机号格式 可以写成NSString的Expense

- (BOOL)isCorrectTelOrPhone:(BOOL)allCheck

{

    if ([NSString isNil:self]) {

        return YES;

    }

    

    NSString *regex = @"^(130|131|132|133|134|135|136|137|138|139|150|151|152|153|155|156|157|158|159|177|180|181|182|183|184|185|186|187|188|189)\\d{8}$";

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

    

    NSString *other;

    if (allCheck) {

        other = @"^(0[0-9]{2,3}\\-)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?$";

        NSPredicate *otherPred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", other];

        if ([otherPred evaluateWithObject:self]) {

            return YES;

        }

    }

    

    

    

    BOOL isMatch = [pred evaluateWithObject:self];

    

    return isMatch;

}


你可能感兴趣的:(手机号格式判断,iOS开发手机号判断)