#define JJPhoneNum @"1[3|5|7|8|][0-9]{9}" //电话号码
- (void)viewDidLoad {
[super viewDidLoad];
NSString * phoneNum = @"157188203788";
NSString * phoneNums = @"15718820378";
NSLog(@"1---%@",[self valiateEnterStr:phoneNum byProvisions:JJPhoneNum]?@"yes":@"no");
NSLog(@"2---%@",[self valiateEnterStr:phoneNums byProvisions:JJPhoneNum]?@"yes":@"no");
}
//方法
- (BOOL)valiateEnterStr:(NSString * )enterString byProvisions:(NSString * )provisions{
NSString * regex = provisions;
NSPredicate * pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
return [pred evaluateWithObject:enterString];
}
网友评论