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; }