The use of the nspredicate of Objective-c grammar

Source: Internet
Author: User

Regular expressions determine the phone number and phone number method:

1 #import<Foundation/Foundation.h>2 /**3 regular Judge cell phone number address format4  */5BOOL Ismobilenumber (NSString *mobilenum) {6     /**7 * Mobile phone number8 * Mobile: 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,1889 * Unicom: 130,131,132,152,155,156,185,186Ten * Telecom: 133,1349,153,180,189 One      */ ANSString *mobile =@"^1 (3[0-9]|5[0-35-9]|8[025-9]) \d{8}$"; -     /** - * China Mobile: the * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188 -      */ -NSString *cm =@"^1 (34[0-8]| ( 3[5-9]|5[017-9]|8[278] \d) \d{7}$"; -     /** + * Unicom: China Unicom - * 130,131,132,152,155,156,185,186 +      */ ANSString *CU =@"^1 (3[0-2]|5[256]|8[56]) \d{8}$"; at     /** - * China Telecom: Telecom - * 133,1349,153,180,189 -      */ -NSString *ct =@"^1 ((33|53|8[09]) [0-9]|349) \d{7}$"; -     /** in * Mainland China fixed and PHS - * Area code: 010,020,021,022,023,024,025,027,028,029 to * Number: seven-bit or eight-bit +      */ -     //nsstring *phs = @ "^0 (10|2[0-5789]|\d{3}) \d{7,8}$"; the      *Nspredicate *regexmobile = [Nspredicate predicatewithformat:@"Self MATCHES%@", MOBILE]; $Nspredicate *REGEXCM = [Nspredicate predicatewithformat:@"Self MATCHES%@", CM];Panax NotoginsengNspredicate *REGEXCU = [Nspredicate predicatewithformat:@"Self MATCHES%@", CU]; -Nspredicate *regexct = [Nspredicate predicatewithformat:@"Self MATCHES%@", CT]; the      +BOOL IsValid =[Regexmobile Evaluatewithobject:mobilenum] A||[REGEXCM Evaluatewithobject:mobilenum] the||[Regexcu Evaluatewithobject:mobilenum] +||[Regexct Evaluatewithobject:mobilenum]; -     returnIsValid; $ } $ intMainintargcConst Char*argv[]) { - @autoreleasepool { -NSString *mobilenumber =@"13523424438"; theBOOL IsValid =Ismobilenumber (mobilenumber); -NSLog (@"is the%@ a valid mobile phone number? %@", Mobilenumber, IsValid?@"is a":@"No");//is aWuyi          theMobilenumber =@"135234244ik"; -IsValid =Ismobilenumber (mobilenumber); WuNSLog (@"is the%@ a valid mobile phone number? %@", Mobilenumber, IsValid?@"is a":@"No");//No -          AboutMobilenumber =@"135234244456776"; $IsValid =Ismobilenumber (mobilenumber); -NSLog (@"is the%@ a valid mobile phone number? %@", Mobilenumber, IsValid?@"is a":@"No");//No -     } -     return 0; A}

The regular expression determines the name (only the Chinese or English letters are allowed, within 10 characters) of the method:

1 + (BOOL) Isvalidatename: (NSString *) name {2     @ "^[\u4e00-\u9fa5a-za-z]{ 1,10}"; 3     Nspredicate *namepredicate = [nspredicate predicatewithformat:@ "selfMATCHES%@" , Nameregex]; 4     return [Namepredicate evaluatewithobject:name]; 5 }

The use of the nspredicate of Objective-c grammar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.