手机号码正则验证(试用版)

前端之家收集整理的这篇文章主要介绍了手机号码正则验证(试用版)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. //手机号码正则验证
  2. - (BOOL)checkTel:(NSString *)str
  3. {
  4. if ([str length] == 0) {
  5. [self showAlertView:@"请输入手机号码"];
  6. return NO;
  7. }
  8. NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
  9. NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
  10. BOOL isMatch = [pred evaluateWithObject:str];
  11. if (!isMatch) {
  12. [self showAlertView:@"手机号码输入有误"];
  13. return NO;
  14. }else {
  15. [self showAlertView:@"修改成功"];
  16. }
  17. return YES;
  18. }
  19.  
  20. - (void)showAlertView:(NSString *)string {
  21. UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:string delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil,nil];
  22. [alertView show];
  23. }

猜你在找的正则表达式相关文章