码迷,mamicode.com
首页 > 移动开发 > 详细

iOS登陆各种验证(持续更新)

时间:2015-09-11 20:42:06      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

 1 //邮箱
 2 + (BOOL) justEmail:(NSString *)email
 3 {
 4     NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
 5     NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
 6     return [emailTest evaluateWithObject:email];
 7 }
 8 
 9 
10 //手机号码验证
11 + (BOOL) justMobile:(NSString *)mobile
12 {
13     //手机号以13, 15,18开头,八个 \d 数字字符
14     NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
15     NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
16     return [phoneTest evaluateWithObject:mobile];
17 }
18 
19 
20 //车牌号验证
21 + (BOOL) justCarNo:(NSString *)carNo
22 {
23     NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";
24     NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
25     NSLog(@"carTest is %@",carTest);
26     return [carTest evaluateWithObject:carNo];
27 }
28 
29 
30 //车型
31 + (BOOL) justCarType:(NSString *)CarType
32 {
33     NSString *CarTypeRegex = @"^[\u4E00-\u9FFF]+$";
34     NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];
35     return [carTest evaluateWithObject:CarType];
36 }
37 
38 
39 //用户名
40 + (BOOL) justUserName:(NSString *)name
41 {
42     NSString *userNameRegex = @"^[A-Za-z0-9]{6,20}+$";
43     NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
44     BOOL B = [userNamePredicate evaluateWithObject:name];
45     return B;
46 }
47 
48 
49 //密码
50 + (BOOL) justPassword:(NSString *)passWord
51 {
52     NSString *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";
53     NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
54     return [passWordPredicate evaluateWithObject:passWord];
55 }
56 
57 
58 //昵称
59 + (BOOL) justNickname:(NSString *)nickname
60 {
61     NSString *nicknameRegex = @"^[\u4e00-\u9fa5]{4,8}$";
62     NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];
63     return [passWordPredicate evaluateWithObject:nickname];
64 }
65 
66 
67 //身份证号
68 + (BOOL) justIdentityCard: (NSString *)identityCard
69 {
70     BOOL flag;
71     if (identityCard.length <= 0) {
72         flag = NO;
73         return flag;
74     }
75     NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
76     NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
77     return [identityCardPredicate evaluateWithObject:identityCard];
78 }

 

iOS登陆各种验证(持续更新)

标签:

原文地址:http://www.cnblogs.com/liaods/p/4801920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!