-(BOOL)isTelNum:(NSString *)num
{
//一个判断是否是移动号码的正则表达式
//130、131、132、152、155、156、185、186
//NSString *regex = @"^(13[0-2]|152|155|156|185|186)[0-9]{8}$";
NSString *regex = @"^(1)[0-9]{10}$";
NSRegularExpression *regularexpression = [[NSRegularExpression alloc]
initWithPattern:regex
options:NSRegularExpressionCaseInsensitive
error:nil];
//无符号整型数据接受匹配的数据的数目
NSUInteger numberofMatch = [regularexpression numberOfMatchesInString:num
options:NSMatchingReportProgress
range:NSMakeRange(0, num.length)];
NSLog(@"================手机号码测试%@=========",num);
//NSLog(@"11位移动手机号码匹配的个数数%d",numberofMatch);
[regularexpression release];
if(numberofMatch > 0)
{
NSLog(@"%@ is phone number: YES", num);
return YES;
}
else
{
NSLog(@"%@ is not phone number:", num);
return NO;
}
}
NSRegularExpression 手机号码判断
最新推荐文章于 2022-03-28 14:36:59 发布