What regular expressions mean in iOS

Source: Internet
Author: User

\d matches any number, i.e. [0-9]

\d+ represents more than 1 digits

\d* flag 0 or more digits

\s represents a delimiter, including spaces, tabs, and line breaks

\s* 0 or more separators

\w represents letters, numbers, and underscores, as well as Unicode characters, which are different in different languages.

\W{4} represents 4 non-whitespace characters

. Represents any one character, not including line breaks

. * denotes any number of characters and does not include line break

^ ([0-9]) denotes the beginning of a number

([0-9]) $ denotes the end of a number

([0-9a-za-z]) denotes a digital letter

| An expression or a relationship, such as a \d|\w that represents a number or letter.

(.| [\ r \ n]) * denotes any number of characters, including line break, greedy scan

(.| [\ r \ n]) *? Represents any number of characters, including line breaks, lazy scan

(?:.|   [\\r\\n]) To (?: The beginning of the grouping information, indicating not to read into the buffer , to avoid the side effects of Rangeatindex calls, you will also encounter such a (?:

For regular expressions, see http://www.cnblogs.com/light169/archive/2006/10/18/532347.html

//Email+ (BOOL) Validateemail: (NSString *) email{NSString*emailregex =@"[A-z0-9a-z._%+-][email protected][a-za-z0-9.-]+\\. [A-za-z] {2,4}"; Nspredicate*emailtest = [Nspredicate predicatewithformat:@"Self MATCHES%@", Emailregex]; return[Emailtest evaluatewithobject:email];}//Mobile phone number verification+ (BOOL) Validatemobile: (NSString *) mobile{//phone number starts with 13, 15, 18, eight \d numeric charactersNSString *phoneregex =@"^ ((13[0-9)) | ( 15[^4,\\D]) | (18[0,0-9])) \\d{8}$"; Nspredicate*phonetest = [Nspredicate predicatewithformat:@"Self MATCHES%@", Phoneregex]; return[Phonetest evaluatewithobject:mobile];}//License plate number Verification+ (BOOL) Validatecarno: (NSString *) carno{NSString*carregex =@"^[\u4e00-\u9fa5]{1}[a-za-z]{1}[a-za-z_0-9]{4}[a-za-z_0-9_\u4e00-\u9fa5]$"; Nspredicate*cartest = [Nspredicate predicatewithformat:@"Self MATCHES%@", Carregex]; NSLog (@"Cartest is%@", cartest); return[Cartest Evaluatewithobject:carno];}//Model+ (BOOL) Validatecartype: (NSString *) cartype{NSString*cartyperegex =@"^[\u4e00-\u9fff]+$"; Nspredicate*cartest = [Nspredicate predicatewithformat:@"Self MATCHES%@", Cartyperegex]; return[Cartest Evaluatewithobject:cartype];}//User name+ (BOOL) Validateusername: (NSString *) name{NSString*usernameregex =@"^[a-za-z0-9]{4,20}+$"; Nspredicate*usernamepredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Usernameregex]; BOOL B=[Usernamepredicate Evaluatewithobject:name]; returnB;}//Password+ (BOOL) ValidatePassword: (NSString *) password{NSString*passwordregex =@"^[a-za-z0-9]{6,20}+$"; Nspredicate*passwordpredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Passwordregex]; return[Passwordpredicate Evaluatewithobject:password];}//Nickname+ (BOOL) Validatenickname: (NSString *) nickname{NSString*nicknameregex =@"([\u4e00-\u9fa5]{2,5}) (&middot;[ \u4e00-\u9fa5]{2,5}) *"; Nspredicate*passwordpredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Nicknameregex]; return[Passwordpredicate evaluatewithobject:nickname];}//ID Number+ (BOOL) Validateidentitycard: (NSString *) identitycard{BOOL flag; if(Identitycard.length <=0) {flag=NO; returnFlag; } nsstring*regex2 =@"^ (\\d{14}|\\d{17}) (\\d|[ XX]) $"; Nspredicate*identitycardpredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Regex2]; return[Identitycardpredicate Evaluatewithobject:identitycard];}//Bank card+ (BOOL) Validatebankcardnumber: (NSString *) bankcardnumber{BOOL flag; if(Bankcardnumber.length <=0) {flag=NO; returnFlag; } nsstring*regex2 =@"^ (\\d{15,30})"; Nspredicate*bankcardpredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Regex2]; return[Bankcardpredicate evaluatewithobject:bankcardnumber];}//Bank card after four people+ (BOOL) Validatebankcardlastnumber: (NSString *) bankcardnumber{BOOL flag; if(Bankcardnumber.length! =4) {flag=NO; returnFlag; } nsstring*regex2 =@"^ (\\d{4})"; Nspredicate*bankcardpredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Regex2]; return[Bankcardpredicate evaluatewithobject:bankcardnumber];}//CVN+ (BOOL) Validatecvncode: (NSString *) cvncode{BOOL flag; if(Cvncode.length <=0) {flag=NO; returnFlag; } nsstring*regex2 =@"^ (\\d{3})"; Nspredicate*cvncodepredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Regex2]; return[Cvncodepredicate Evaluatewithobject:cvncode];}//Month+ (BOOL) Validatemonth: (NSString *) month{BOOL flag; if(!month.length = =2) {flag=NO; returnFlag; } nsstring*regex2 =@"(^ (0) ([0-9]) $) | (^ (1) ([0-2])"; Nspredicate*monthpredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Regex2]; return[Monthpredicate evaluatewithobject:month];}//Month+ (BOOL) Validateyear: (NSString *) year{BOOL flag; if(!year.length = =2) {flag=NO; returnFlag; } nsstring*regex2 =@"^ ([1-3]) ([0-9]) $"; Nspredicate*yearpredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Regex2]; return[Yearpredicate evaluatewithobject:year];}//Verifycode+ (BOOL) Validateverifycode: (NSString *) verifycode{BOOL flag; if(!verifycode.length = =6) {flag=NO; returnFlag; } nsstring*regex2 =@"^ (\\d{6})"; Nspredicate*verifycodepredicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", Regex2]; return[Verifycodepredicate Evaluatewithobject:verifycode];}

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.