首页 > 其他分享 >IOS正则判断手机号码,电话号码函数

IOS正则判断手机号码,电话号码函数

时间:2022-12-09 15:07:31浏览次数:42  
标签:NSPredicate MATCHES IOS NSString mobileNum 正则 predicateWithFormat 手机号码 YES

1. // 正则判断手机号码地址格式  
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. }

标签:NSPredicate,MATCHES,IOS,NSString,mobileNum,正则,predicateWithFormat,手机号码,YES
From: https://blog.51cto.com/u_15907570/5925296

相关文章

  • IOS之【ios程序的生命周期】
    文件#import“OneAppDelegate.h"#import“OneViewController.h"@implementation-(void)dealloc{_windowrelease];[_viewControllerrelease];superdealloc];}#prag......
  • IOS之【UIToolbar】
    #import"OneViewController.h"@interfaceOneViewController()@end@implementation-(void)add{NSLog(@"添加");}-(void)delete{NSLog(@"删除");}-(void)view......
  • IOS之【属性列表】
    @implementation-(void)viewDidLoad{[superviewDidLoad];[selfwritePerson];}尝试写Person//不能通过writeToFile将一个普通对象写入文件中//writeToFi......
  • IOS之【NSUserDefaults】
    @implementation-(void)viewDidLoad{[superviewDidLoad];selfread];}读取偏好设置-(void)read{NSUserDefaults*defaults=[NSUserDefaultsstandardUserDefa......
  • 使用VMware时Intel VT-x禁用的问题,顺便检查Win10使用命令行进入BIOS方式
     如图所示:此主机支持IntelVT-x,但IntelVT-x处于禁用状态。如果已在BIOS/固件设置中禁用IntelVT-x,或主机自更改此设置后从未重新启动,则IntelVT-x可能被禁用......
  • 正则表达式
    正则表达式#私藏项目实操分享#//varreg=/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1......
  • iOS开发_取出UIColor上对应rgba的值
    UIColor+Extension.h#import<UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interfaceUIColor(Extension)@property(nonatomic,assign,readonly)CGFloatred;@......
  • iOS开发_修改颜色Color
    UIColor+Modify.h#import<UIKit/UIKit.h>@interfaceUIColor(Modify)/***@brief反转颜色**@return反转处理后的颜色*/-(UIColor*)inverted;/*......
  • iOS开发_颜色转十六进制字符串
    /***@briefUIColor转#ffffff格式的16进制字符串**@return格式为#ff0000的16进制字符串*/-(NSString*)hex_String{constCGFloat*components=C......
  • 实现在windows、linux下上传ios app到App Store​
     我们知道发布一个app,一般是用到苹果的applicationloader助手上传应用,用过的都知道使用起来很繁琐,经常出错。而且只能运行在mac系统上,需要一定的硬件条件。​  前......