手机号正则表达式

2017-06-29  本文已影响18人  Hris

#pragma mark 正则表达式判断手机号

+(BOOL)checkPhoneNumInput:(NSString *)numStr

{

NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|7[06-8]|8[0-9])\\d{8}$";

NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|78|8[2-478])\\d)\\d{7}$";

NSString * CU = @"^1(3[0-2]|5[256]|7[06]|8[56])\\d{8}$";

NSString * CT = @"^1((33|53|77|8[019])[0-9]|349)\\d{7}$";

NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];

NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];

NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];

NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];

BOOL res1 = [regextestmobile evaluateWithObject:numStr];

BOOL res2 = [regextestcm evaluateWithObject:numStr];

BOOL res3 = [regextestcu evaluateWithObject:numStr];

BOOL res4 = [regextestct evaluateWithObject:numStr];

if (res1 || res2 || res3 || res4 )

{

return YES;

}

else

{

return NO;

}

}

上一篇下一篇

猜你喜欢

热点阅读