ios处理判断手机号码的正则表达式,基本上包含全部的手机号段
2015-07-02 08:46
609 查看
原文:http://blog.csdn.net/z343929897/article/details/8099086
- (BOOL)checkTel:(NSString *)str
{
if ([str length] == 0) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"data_null_prompt", nil)message:NSLocalizedString(@"tel_no_null", nil) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
return NO;
}
//1[0-9]{10}
//^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$
// NSString *regex = @"[0-9]{11}";
NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch = [pred evaluateWithObject:str];
if (!isMatch) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的手机号码"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
return NO;
}
return YES;
}
- (BOOL)checkTel:(NSString *)str
{
if ([str length] == 0) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"data_null_prompt", nil)message:NSLocalizedString(@"tel_no_null", nil) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
return NO;
}
//1[0-9]{10}
//^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$
// NSString *regex = @"[0-9]{11}";
NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch = [pred evaluateWithObject:str];
if (!isMatch) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的手机号码"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
return NO;
}
return YES;
}
相关文章推荐
- Nagios客户端安装
- 再造轮子之网易彩票-第一季(IOS 篇 by sixleaves)
- Nagios服务端安装
- AudioServicesPlaySystemSound 系统声音提示 iOS iPad
- iOS 性能分析指南(一)
- iOS7 系统导航栏的标准配置
- iOS开发范例实战宝典(基础篇)
- IOS 笔试题(一)
- IOS 笔试题(二)
- iOS之内存管理
- iOS之内存管理
- iOS学习5_控制器的创建方式和控制器view的创建
- iOS学习5_控制器的创建方式和控制器view的创建
- iOS and OS X Network Programming Cookbook |Creating an echo Client(CFSocket)
- iOS github开源框架
- iOS计算文本尺寸
- Xcode5.1离线下载安装及使用iOS5模拟器进行开发调试的方法
- iOS开发ARC内存管理技术要点
- iOS开发进阶
- iOS and OS X Network Programming Cookbook |Creating an echo Client(Bonjour)