1. // 正则判断手机号码地址格式标签:NSPredicate,MATCHES,IOS,NSString,mobileNum,正则,predicateWithFormat,手机号码,YES From: https://blog.51cto.com/u_15907570/5925296
2. - (BOOL)isMobileNumber:(NSString *)mobileNum
3. {
4. /**
5. * 手机号码
6. * 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
7. * 联通:130,131,132,152,155,156,185,186
8. * 电信:133,1349,153,180,189
9. */
10. NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
11. /**
12. 10 * 中国移动:China Mobile
13. 11 * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
14. 12 */
15. NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
16. /**
17. 15 * 中国联通:China Unicom
18. 16 * 130,131,132,152,155,156,185,186
19. 17 */
20. NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
21. /**
22. 20 * 中国电信:China Telecom
23. 21 * 133,1349,153,180,189
24. 22 */
25. NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
26. /**
27. 25 * 大陆地区固话及小灵通
28. 26 * 区号:010,020,021,022,023,024,025,027,028,029
29. 27 * 号码:七位或八位
30. 28 */
31. // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
32.
33. NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
34. NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
35. NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
36. NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
37.
38. if (([regextestmobile evaluateWithObject:mobileNum] == YES)
39. || ([regextestcm evaluateWithObject:mobileNum] == YES)
40. || ([regextestct evaluateWithObject:mobileNum] == YES)
41. || ([regextestcu evaluateWithObject:mobileNum] == YES))
42. {
43. return YES;
44. }
45. else
46. {
47. return NO;
48. }
49. }