我是靠谱客的博主 美丽花卷,这篇文章主要介绍ios常用正则表达式与左对齐的UIAlertView,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
+(BOOL)alertPhoneString:(NSString *)text ifalert:(BOOL)ifalert {//判断是手机号码 if (text.length==0) { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请填写手机号码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; [alert release]; return NO; } NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\b(1)[3458][0-9]{9}\b" options:NSRegularExpressionCaseInsensitive error:nil]; NSUInteger numberOfMatches = [regex numberOfMatchesInString:text options:0 range:NSMakeRange(0, [text length])]; if(numberOfMatches !=1 ){ //手机号码错误 if (ifalert) { //需要提醒手机号错误 UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请确认手机号码是否正确" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; [alert release]; } return NO; } else return YES; } +(BOOL)alertEmail:(NSString *)EmailAddress ifalert:(BOOL)ifalert { //判断邮箱是否正确 if (EmailAddress.length==0) { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请填写邮箱!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; [alert release]; return NO; } NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}" options:NSRegularExpressionCaseInsensitive error:nil]; NSUInteger numberOfMatches = [regex numberOfMatchesInString:EmailAddress options:0 range:NSMakeRange(0, [EmailAddress length])]; if(numberOfMatches !=1 ){ if (ifalert) { UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"邮箱格式不正确" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; [alert release]; } return NO; } else return YES; } +(BOOL)alertInputCardNo:(NSString *)string { //判断输入是否是正整数 NSCharacterSet *cs; cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789n"] invertedSet]; NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; BOOL basicTest = [string isEqualToString:filtered]; if(!basicTest) { UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"输入只能为数字" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; [alert release]; return NO; } else return YES; } +(BOOL)alertresult:(NSString *)message title:(NSString *)title { //message的格式为 /n*****/n****/n*** 该alert的显示格式为 // ***** // **** // *** UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; for( UIView * view in alert.subviews ) { if( [view isKindOfClass:[UILabel class]] ) { UILabel* label = (UILabel*) view; if (label.text!=alert.title) { label.textAlignment = UITextAlignmentLeft; } } } [alert show]; [alert release]; return YES; }


最后

以上就是美丽花卷最近收集整理的关于ios常用正则表达式与左对齐的UIAlertView的全部内容,更多相关ios常用正则表达式与左对齐内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部