Regular expression limit account password Mailbox ID phone number of the relevant code _ regular expressions

Source: Internet
Author: User

Nonsense to say, directly to everyone to implement this function of the regular expression code, the specific code as follows:

#import <Foundation/Foundation.h> int Main () {//? = {0,1}//* = = {0, Infinity}//+ = {1, infinity}//\d = = [0-9]///\w = =
[a-za-z_0-9]//* means dispensable//[a|b|c]+ indicates that three at least one or more times///Check phone number is correct nsstring *tel = @ "";
Regular expression NSString *regex = @ "^\\d*$";
NSString *regex = @ "^[0-9]{3,4}-[0-9]{7,8}$"; Nspredicate *predicate = [nspredicate predicatewithformat:@ ' SELF matches%@ ', regex];//create predicate NSLog (@) that needs to satisfy the above regular expression
:%d ", [predicate evaluatewithobject:tel]);
Username (first must be a letter, 6-16 digits, can only have letters, numbers or underscores) nsstring *user = @ "m54355";
NSString *regex1 = @ "^[a-za-z]\\w{5,15}$";
Nspredicate *predicate1 = [nspredicate predicatewithformat:@ "SELF matches%@", regex1];
NSLog (@ "This phone number:%d", [predicate1 Evaluatewithobject:user]);
ID//NSString *user1 = @ "610125199301300814";
NSString *regex2 = @ "^\\d{17}[\\dxx]$";
Nspredicate *predicate2 = [nspredicate predicatewithformat:@ "SELF matches%@", Regex2];
NSLog (@ "This ID:%d", [Predicate2 evaluatewithobject:user1]);
Mailbox NSString *mailbox = @ "101707383@qq.com"; NssTring *regex3 = @ "^[a-za-z0-9._%+-]+@[a-za-z0-9.-]+\\. [A-za-z]
{2,4}$ ";
Nspredicate *predicate3 = [nspredicate predicatewithformat:@ "SELF matches%@", regex3];
NSLog (@ "This mailbox:%d", [Predicate3 Evaluatewithobject:mailbox]);
Mobile phone number//NSString *phone = @ "18709259205";
NSString *regex4 = @ "^1[3|4|5|7|8]\\d{9}$";
Nspredicate *predicate4 = [nspredicate predicatewithformat:@ "SELF matches%@", regex4];
NSLog (@ "The Mobile:%d", [Predicate4 Evaluatewithobject:phone]); if ([predicate1 evaluatewithobject:user] = = 1) {if ([predicate3 evaluatewithobject:mailbox] = = 1) {NSLog (@ login succeeded);}
else{NSLog (@ "error");} return 0; }

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.