幾個iosRegex 判斷郵箱 手機號碼 社會安全號碼碼

來源:互聯網
上載者:User

標籤:

  [objc] view plaincopy 
  1. //判斷是否為郵箱  
  2. - (BOOL) validateEmail: (NSString *) candidate  
  3. {  
  4.     NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";  
  5.     NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];  
  6.     return [emailTest evaluateWithObject:candidate];  
  7. }  
[objc] view plaincopy 
  1. // 正則判斷手機號碼地址格式  
  2. - (BOOL)isMobileNumber:(NSString *)mobileNum  
  3. {  
  4.        /** 
  5.         * 手機號碼 
  6.         * 移動:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188 
  7.         * 聯通:130,131,132,152,155,156,185,186 
  8.         * 電信:133,1349,153,180,189 
  9.         */  
  10.        NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";  
  11.        /** 
  12.         10         * 中國移動:China Mobile 
  13.         11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188 
  14.         12         */  
  15.        NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";  
  16.        /** 
  17.         15         * 中國聯通:China Unicom 
  18.         16         * 130,131,132,152,155,156,185,186 
  19.         17         */  
  20.        NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";  
  21.        /** 
  22.         20         * 中國電信:China Telecom 
  23.         21         * 133,1349,153,180,189 
  24.         22         */  
  25.        NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";  
  26.        /** 
  27.         25         * 大陸地區固話及小靈通 
  28.         26         * 區號:010,020,021,022,023,024,025,027,028,029 
  29.         27         * 號碼:七位或八位 
  30.         28         */  
  31.       // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";  
  32.       
  33.      NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];  
  34.      NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];  
  35.      NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];  
  36.      NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];  
  37.       
  38.     if (([regextestmobile evaluateWithObject:mobileNum] == YES)  
  39.     || ([regextestcm evaluateWithObject:mobileNum] == YES)  
  40.     || ([regextestct evaluateWithObject:mobileNum] == YES)  
  41.     || ([regextestcu evaluateWithObject:mobileNum] == YES))  
  42.     {  
  43.         return YES;  
  44.     }  
  45.     else   
  46.     {  
  47.         return NO;  
  48.     }  
  49. }  
[objc] view plaincopy 
  1. //社會安全號碼  
  2. + (BOOL) validateIdentityCard: (NSString *)identityCard  
  3. {  
  4.     BOOL flag;  
  5.     if (identityCard.length <= 0) {  
  6.         flag = NO;  
  7.         return flag;  
  8.     }  
  9.     NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";  
  10.     NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];  
  11.     return [identityCardPredicate evaluateWithObject:identityCard];  
  12. }  

幾個iosRegex 判斷郵箱 手機號碼 社會安全號碼碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.