iOS 判断手机号的正则表达式

现在的app更多的是采用手机号进行注册登录,所以对于手机号的对错进行判断就成了现在许多程序猿必须要做的功能,下面的就是对手机号判断的方法:

NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d{8}$";

NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\\d{8}$)|(^1705\\d{7}$)";

NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\\d{8}$)|(^1709\\d{7}$)";

NSString *CT = @"(^1(33|53|77|8[019])\\d{8}$)|(^1700\\d{7}$)";

NSPredicate *regextestmobile1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];

NSPredicate *regextestcm1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];

NSPredicate *regextestcu1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];

NSPredicate *regextestct1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];

if (self._textfiled.text.length !=11 ) {

UIAlertView * alert2 = [[UIAlertView alloc]initWithTitle:nil message:@"您还没有输入电话号" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

[alert2 show];

}

if (([regextestmobile1 evaluateWithObject:self._textfiled.text] == YES)

|| ([regextestcm1 evaluateWithObject:self._textfiled.text] == YES)

|| ([regextestct1 evaluateWithObject:self._textfiled.text] == YES)

|| ([regextestcu1 evaluateWithObject:self._textfiled.text] == YES)){

这里写判断手机号正确后的逻辑

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容