免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1441 | 回复: 1
打印 上一主题 下一主题

[iOS] 手机号码 验证 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-06-30 09:52 |只看该作者 |倒序浏览
[Objective-C]代码
  1. + (BOOL) isMobileNumber:(NSString *)mobileNum;
  2. + (BOOL) isMobileNumber:(NSString *)mobileNum{
  3.     /**
  4.     * 手机号码
  5.     * 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
  6.     * 联通:130,131,132,152,155,156,185,186
  7.     * 电信:133,1349,153,180,189
  8.     */
  9.     NSString *MOBILE = @"^1(3[0-9]|5[0-35-9]|7[06-8]|8[0125-9])\\d{8}$";
  10.     /**
  11.     10         * 中国移动:China Mobile
  12.     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,178,182,187,188
  13.     12         */
  14.     NSString *CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|78|8[278])\\d)\\d{7}$";
  15.     /**
  16.     15         * 中国联通:China Unicom
  17.     16         * 130,131,132,152,155,156,176,185,186
  18.     17         */
  19.     NSString *CU = @"^1(3[0-2]|5[256]|76|8[56])\\d{8}$";
  20.     /**
  21.     20         * 中国电信:China Telecom
  22.     21         * 133,1349,153,177,180,189
  23.     22         */
  24.     NSString *CT = @"^1((33|53|77|8[09])[0-9]|349)\\d{7}$";
  25.     /**
  26.     25         * 大陆地区固话及小灵通
  27.     26         * 区号:010,020,021,022,023,024,025,027,028,029
  28.     27         * 号码:七位或八位
  29.     28         */
  30.     // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";

  31.     NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@" , MOBILE];
  32.     NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@" , CM];
  33.     NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@" , CU];
  34.     NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@" , CT];

  35.     return [regextestmobile evaluateWithObject:mobileNum]
  36.             || [regextestcm evaluateWithObject:mobileNum]
  37.             || [regextestct evaluateWithObject:mobileNum]
  38.             || [regextestcu evaluateWithObject:mobileNum];
  39. }
复制代码

论坛徽章:
39
白银圣斗士
日期:2015-11-24 10:40:40酉鸡
日期:2015-03-20 14:15:44寅虎
日期:2015-03-20 14:13:59午马
日期:2015-03-20 14:13:16白羊座
日期:2015-03-20 14:12:54金牛座
日期:2015-03-20 14:12:09双子座
日期:2015-03-20 14:11:57巨蟹座
日期:2015-03-20 14:11:44狮子座
日期:2015-03-20 14:11:29亥猪
日期:2015-03-20 14:16:24戌狗
日期:2015-03-20 14:16:40申猴
日期:2015-03-20 14:17:05
2 [报告]
发表于 2015-06-30 15:12 |只看该作者
170出来这么久了,你这代码还不支持
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP