美文网首页
iOS 正则表达式验证手机号

iOS 正则表达式验证手机号

作者: 谁说_ | 来源:发表于2017-06-30 12:29 被阅读0次

-(void)press{

NSString *checkString = text.text;

// 1.创建正则表达式,

//NSString *pattern = @"^\\d{14}[[0-9],0-9xX]$";

NSString *pattern = @"^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[57])|(17[013678]))\\d{8}$";

// 1.1将正则表达式设置为OC规则

NSPredicate * preURL =[NSPredicate predicateWithFormat:@"self matches%@",pattern ];

bool b1 = [preURL evaluateWithObject:checkString];

if (b1) {

NSLog(@"手机号验证正确");

}else{

NSLog(@"手机号验证不正确");

}

}

相关文章

网友评论

      本文标题:iOS 正则表达式验证手机号

      本文链接:https://www.haomeiwen.com/subject/arkmcxtx.html