通过系统自带的NSPredicate使用正则表达式

  1. NSString *regex =[NSString stringWithFormat:@"^1(3[4-9]|5[012789]|8[2378]|47)\\d{8}$"];  
  2. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];  

  3. BOOL isMatch = [predicate evaluateWithObject:editPhoneField.text]; 

posted @ 2016-09-05 15:50  HZ_张雷  阅读(220)  评论(0编辑  收藏  举报