最全的手机号验证
// 正则判断手机号码地址格式
+ (BOOL)isMobileNumber:(NSString *)mobileNum
{
/**
* 手机号码
* 移动:134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,178(4G),147,1705
* 联通:130,131,132,152,155,156,185,186,1709,176,145
* 电信:133,153,180,189,1700,177,181
*/
NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|7[06-8]|8[0-9])\\d{8}$";
/**
* 中国移动:China Mobile
* 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,178(4G),147,1705
*/
NSString * CM = @"^1(705|(3[4-9]|5[0127-9]|78|8[23478])\\d)\\d{7}$";
/**
* 中国联通:China Unicom
* 130,131,132,152,155,156,185,186,1709,176,145
*/
NSString * CU = @"^1((3[0-2]|45|5[256]|8[56])[0-9]|709)\\d{7}$";
/**
* 中国电信:China Telecom
* 133,153,180,189,1700,177,181
*/
NSString * CT = @"^1((33|53|77|8[019])[0-9]|700)\\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];
if (([regextestmobile evaluateWithObject:mobileNum] == YES)
|| ([regextestcm evaluateWithObject:mobileNum] == YES)
|| ([regextestct evaluateWithObject:mobileNum] == YES)
|| ([regextestcu evaluateWithObject:mobileNum] == YES))
{
return YES;
}
else
{
return NO;
}
}
更多手机福利关注 appshi6