NSString+Check.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // NSString+Check.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/8/15.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "NSString+Check.h"
  9. @implementation NSString (Check)
  10. -(BOOL)checkPhoneNumInput{
  11. NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9]|70|77)\\d{8}$";
  12. NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
  13. NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
  14. NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
  15. // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
  16. NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
  17. NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
  18. NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
  19. NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
  20. BOOL res1 = [regextestmobile evaluateWithObject:self];
  21. BOOL res2 = [regextestcm evaluateWithObject:self];
  22. BOOL res3 = [regextestcu evaluateWithObject:self];
  23. BOOL res4 = [regextestct evaluateWithObject:self];
  24. if (res1 || res2 || res3 || res4 ){
  25. return YES;
  26. }else{
  27. return NO;
  28. }
  29. }
  30. @end