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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过系统自带的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]; 

以上是关于通过系统自带的NSPredicate使用正则表达式的主要内容,如果未能解决你的问题,请参考以下文章