验证手机号
2016-05-11 15:11
429 查看
/** * 手机号码验证 * * @param mobileNumbel 传入的手机号码 * * @return 格式正确返回true 错误 返回fals */ + (BOOL) isMobile:(NSString *)mobileNumbel{ if (mobileNumbel.length < 11) { return @"手机号长度只能是11位"; } else { /** * 移动号段正则表达式 */ 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 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM_NUM]; BOOL isMatch1 = [pred1 evaluateWithObject:mobileNumbel]; NSPredicate *pred2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU_NUM]; BOOL isMatch2 = [pred2 evaluateWithObject:mobileNumbel]; NSPredicate *pred3 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT_NUM]; BOOL isMatch3 = [pred3 evaluateWithObject:mobileNumbel]; if (isMatch1 || isMatch2 || isMatch3) { return nil; } else { return @"请输入正确的电话号码"; } } return nil; }
相关文章推荐
- Swift 语法
- Swift译前说明
- iOS动画 属性属性解析
- iOS 检查更新
- iOS多线程开发
- iOS 不规则瀑布流
- IOS中获取各种文件的目录路径的方法
- iOS 理解证书与描述文件
- ios layer图层排序
- IOS 的 KVO机制
- IOS 解决后台计数器不准确问题
- iOS 自定义视频播放器
- iOS设备唯一标识符
- IOS开发 视图重叠时设置交互的优先级__userInteractionEnabled用户交互
- iOS 音乐
- ios导航栏rightBarButtonItems多个按钮自定义设置
- MLeaksFinder:精准 iOS 内存泄露检测工具
- IOS开发教程01
- 不要在init和dealloc函数中使用accessor
- 《Motion Design for iOS》(十五)