判断是否为有效电话号码的方法
2016-09-23 18:19
225 查看
/**
*
移动号段正则表达式
*/
NSString *CM_NUM =@"^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
/**
*
联通号段正则表达式
*/
NSString *CU_NUM =@"^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
/**
*
电信号段正则表达式
*/
NSString *CT_NUM =@"^((133)|(153)|(177)|(18[0,1,9]))\\d{8}$";
NSPredicate *pred1 = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@", CM_NUM];
BOOL isMatch1 = [pred1evaluateWithObject:mobile];
NSPredicate *pred2 = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@", CU_NUM];
BOOL isMatch2 = [pred2evaluateWithObject:mobile];
NSPredicate *pred3 = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@", CT_NUM];
BOOL isMatch3 = [pred3evaluateWithObject:mobile];
if (isMatch1 || isMatch2 || isMatch3) {
returnnil;
}
else {
return@"请输入正确的电话号码";
}
*
移动号段正则表达式
*/
NSString *CM_NUM =@"^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
/**
*
联通号段正则表达式
*/
NSString *CU_NUM =@"^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
/**
*
电信号段正则表达式
*/
NSString *CT_NUM =@"^((133)|(153)|(177)|(18[0,1,9]))\\d{8}$";
NSPredicate *pred1 = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@", CM_NUM];
BOOL isMatch1 = [pred1evaluateWithObject:mobile];
NSPredicate *pred2 = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@", CU_NUM];
BOOL isMatch2 = [pred2evaluateWithObject:mobile];
NSPredicate *pred3 = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@", CT_NUM];
BOOL isMatch3 = [pred3evaluateWithObject:mobile];
if (isMatch1 || isMatch2 || isMatch3) {
returnnil;
}
else {
return@"请输入正确的电话号码";
}
相关文章推荐
- [第一次机房收费系统]查询余额优化
- Linux命令(29):free
- java语法体系
- 组合模式/composite模式/对象结构型模式
- android自定义View
- 栈区,堆区,全局区,文字常量区,程序代码区详解(程序中不同类型数据所在区)
- 仿iOS弹出Dialog
- 类和对象的基础2——对象的生与死(构造函数和析构函数)
- 为您详细比较三个 CSS 预处理器(框架):Sass、LESS 和 Stylus
- 代码区,初始化全局数据区,BSS,堆区,栈区,程序环境变量区简介
- listview,gridview等可通用的万能适配器,继承此类即可
- 【基础】嵌入式浏览器移植基本要素
- 23. Merge k Sorted Lists(heap)
- MT6735平台屏幕旋转90度
- ES6学习笔记(一)let const
- JNI中map转HashMap
- 关于指针,可能是网上最详细的讲解了
- PAT(A) - 1094. The Largest Generation (25)
- Java中精确到(保留)小数点后几位的方法
- SpringMVC3.0+MyIbatis3.0(分页示例)【转】