iOS 利用正则函数判断手机号码(13,15,17,18字段)
2016-07-22 本文已影响36人
孟维学
NSString*regex =@"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]|(17[0-9])))\\d{8}$";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@", regex];
BOOLisMatch = [predevaluateWithObject:self.numtextfild.text];
if(!isMatch) {
UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"请输入正确的手机号码"delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil,nil];
alert.tag=4369;
[alertshow];
return;
}