iOS开发判断手机号格式
2016-01-07 15:39
489 查看
// 判断手机号格式 可以写成NSString的Expense
- (BOOL)isCorrectTelOrPhone:(BOOL)allCheck
{
if ([NSString
isNil:self]) {
return YES;
}
NSString *regex =
@"^(130|131|132|133|134|135|136|137|138|139|150|151|152|153|155|156|157|158|159|177|180|181|182|183|184|185|186|187|188|189)\\d{8}$";
NSPredicate *pred = [NSPredicate
predicateWithFormat:@"SELF MATCHES %@", regex];
NSString *other;
if (allCheck) {
other = @"^(0[0-9]{2,3}\\-)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?$";
NSPredicate *otherPred = [NSPredicate
predicateWithFormat:@"SELF MATCHES %@", other];
if ([otherPred
evaluateWithObject:self]) {
return
YES;
}
}
BOOL isMatch = [pred
evaluateWithObject:self];
return isMatch;
}
- (BOOL)isCorrectTelOrPhone:(BOOL)allCheck
{
if ([NSString
isNil:self]) {
return YES;
}
NSString *regex =
@"^(130|131|132|133|134|135|136|137|138|139|150|151|152|153|155|156|157|158|159|177|180|181|182|183|184|185|186|187|188|189)\\d{8}$";
NSPredicate *pred = [NSPredicate
predicateWithFormat:@"SELF MATCHES %@", regex];
NSString *other;
if (allCheck) {
other = @"^(0[0-9]{2,3}\\-)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?$";
NSPredicate *otherPred = [NSPredicate
predicateWithFormat:@"SELF MATCHES %@", other];
if ([otherPred
evaluateWithObject:self]) {
return
YES;
}
}
BOOL isMatch = [pred
evaluateWithObject:self];
return isMatch;
}
相关文章推荐
- iOS 陀螺仪 加速计
- iOS高德定位和自带逆地理编码进行坐标转换
- 【有疑问,待解决】iOS 9 memory leak
- ios8 gps定位不好用
- zposition是啥东西?
- iOS开发多线程篇—多线程简介
- iOS 通知对应的方法多次执行问题
- [黑马IOS自学第十七篇]OC BLOCK学习
- iOS_24_画画板(含取色板)
- bios错误信息
- iOS 火星坐标系转换 扩展 源代码
- iOS项目
- 如何实现例如iOS的listview 的弹性效果
- IOS时间戳
- iOS 开发中遇见的小bug
- iOS精益求精 设计模式
- iOS 解决导航栏隐藏后显示的问题
- iOS开发怎么使用copy关键字
- NSScanner类的基本用法
- iOS学习笔记55- iOS项目集成ShareSDK实现第三方登录、分享、关注等功能。