常用得正则表达式案例

前端之家收集整理的这篇文章主要介绍了常用得正则表达式案例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1 NSString * regex = @"(^[A-Za-z0-9]{6,15}$)";
2 NSPredicate * pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
3 BOOLisMatch = [pred evaluateWithObject:@"123456ABCde"];

01 下面是一些常用的正则表达式
02 //邮箱
03 + () validateEmail:(NSString *)email
04 {
05 NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"06 NSPredicate *emailTest = [NSPredicate predicateWithFormat:@
07 return[emailTest evaluateWithObject:email];
08 }
09
10
11 //手机号码验证
12 ) validateMobile:(NSString *)mobile
13 {
14 //手机号以13, 15,18开头,八个 \d 数字字符
15 NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$"16 NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@
17 [phoneTest evaluateWithObject:mobile];
18 19 20 21 //车牌号验证
22 ) validateCarNo:(NSString *)carNo
23 24 NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";
25 NSPredicate *carTest = [NSPredicate predicateWithFormat:@
26 NSLog(@"carTest is %@"
27 [carTest evaluateWithObject:carNo];
28 29 30 31 //车型
32 ) validateCarType:(NSString *)CarType
33 34 NSString *CarTypeRegex = @"^[\u4E00-\u9FFF]+$"35
36 [carTest evaluateWithObject:CarType];
37 }
38 39 40 //用户名
41 ) validateUserName:(NSString *)name
42 43 NSString *userNameRegex = @"^[A-Za-z0-9]{6,20}+$"44 NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@
45 B = [userNamePredicate evaluateWithObject:name];
46 B;
47 48 49 50 //密码
51 ) validatePassword:(NSString *)passWord
52 53 NSString *passWordRegex = @"^[a-zA-Z0-9]{6,monospace!important; font-size:1em!important; min-height:inherit!important; display:block!important">54 NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@
55 [passWordPredicate evaluateWithObject:passWord];
56 57 58 59 //昵称
60 ) validateNickname:(NSString *)nickname
61 62 NSString *nicknameRegex = @"^[\u4e00-\u9fa5]{4,8}$"63
64 [passWordPredicate evaluateWithObject:nickname];
65 66 67 68 //身份证号
69 ) validateIdentityCard: (NSString *)identityCard
70 71 flag;
72 if(identityCard.length <= 0) {
73 flag = NO;
74 flag;
75 76 NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$"77 NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@
78 [identityCardPredicate evaluateWithObject:identityCard];
79 }
原文链接:https://www.f2er.com/regex/361562.html

猜你在找的正则表达式相关文章