iOS??????ü??????????????У??
???????????? ???????[ 2015/1/27 17:48:08 ] ??????????????? iOS ??????
????VerifyRegexTool.m???????
1#import"VerifyRegexTool.h"
2
3@implementationVerifyRegexTool
4
5//?????????
6+(BOOL)verifyIsNotEmpty:(NSString*)str
7{
8if(!str)returnNO;
9
10str=[strstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]];
11if(![strisEqualToString:@""]){
12returnYES;
13}else{
14returnNO;
15}
16}
17
18//???????
19+(BOOL)verifyText:(NSString*)textwithRegex:(NSString*)regex
20{
21return[[textstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]]isMatchedByRegex:regex];
22}
23
24//???????
25//???????????1???
26//1.?????????18λ???17λ????????????????λ???????????X
27//2.???λ???????????????е?????11??12??13??14??15??21??22??23??31??32??33??34??35??36??37??41??42??43??44??45??46??50??51??52??53??54??61??62??63??64??65??71??81??82??91
28//3.??7????14λ?????????????7????10λ?????????11??12λ????·????Χ?01-12??13??14λ??????????
29//4.??17λ????????????????????????
30//5.??18λ??17λ??У??λ
31//?????£?
32//??1??У???=(n1+n11)*7+(n2+n12)*9+(n3+n13)*10+(n4+n14)*5+(n5+n15)*8+(n6+n16)*4+(n7+n17)*2+n8+n9*6+n10*3??????n???????????λ??????
33//??2????????У???%11
34//??3??????????0??У??λ??1???????1??10У??λ???????“0X98765432”(?????????)???????λ?????????????????3??У??λ??9??
35//6.???????????λ??????19??20
36+(BOOL)verifyIDCardNumber:(NSString*)value
37{
38value=[valuestringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];
39if([valuelength]!=18){
40returnNO;
41}
42NSString*mmdd=@"(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8])))";
43NSString*leapMmdd=@"0229";
44NSString*year=@"(19|20)[0-9]{2}";
45NSString*leapYear=@"(19|20)(0[48]|[2468][048]|[13579][26])";
46NSString*yearMmdd=[NSStringstringWithFormat:@"%@%@"??year??mmdd];
47NSString*leapyearMmdd=[NSStringstringWithFormat:@"%@%@"??leapYear??leapMmdd];
48NSString*yyyyMmdd=[NSStringstringWithFormat:@"((%@)|(%@)|(%@))"??yearMmdd??leapyearMmdd??@"20000229"];
49NSString*area=@"(1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5]|82|[7-9]1)[0-9]{4}";
50NSString*regex=[NSStringstringWithFormat:@"%@%@%@"??area??yyyyMmdd??@"[0-9]{3}[0-9Xx]"];
51
52NSPredicate*regexTest=[NSPredicatepredicateWithFormat:@"SELFMATCHES%@"??regex];
53if(![regexTestevaluateWithObject:value]){
54returnNO;
55}
56intsummary=([valuesubstringWithRange:NSMakeRange(0??1)].intValue+[valuesubstringWithRange:NSMakeRange(10??1)].intValue)*7
57+([valuesubstringWithRange:NSMakeRange(1??1)].intValue+[valuesubstringWithRange:NSMakeRange(11??1)].intValue)*9
58+([valuesubstringWithRange:NSMakeRange(2??1)].intValue+[valuesubstringWithRange:NSMakeRange(12??1)].intValue)*10
59+([valuesubstringWithRange:NSMakeRange(3??1)].intValue+[valuesubstringWithRange:NSMakeRange(13??1)].intValue)*5
60+([valuesubstringWithRange:NSMakeRange(4??1)].intValue+[valuesubstringWithRange:NSMakeRange(14??1)].intValue)*8
61+([valuesubstringWithRange:NSMakeRange(5??1)].intValue+[valuesubstringWithRange:NSMakeRange(15??1)].intValue)*4
62+([valuesubstringWithRange:NSMakeRange(6??1)].intValue+[valuesubstringWithRange:NSMakeRange(16??1)].intValue)*2
63+[valuesubstringWithRange:NSMakeRange(7??1)].intValue*1+[valuesubstringWithRange:NSMakeRange(8??1)].intValue*6
64+[valuesubstringWithRange:NSMakeRange(9??1)].intValue*3;
65NSIntegerremainder=summary%11;
66NSString*checkBit=@"";
67NSString*checkString=@"10X98765432";
68checkBit=[checkStringsubstringWithRange:NSMakeRange(remainder??1)];//?ж?У??λ
69return[checkBitisEqualToString:[[valuesubstringWithRange:NSMakeRange(17??1)]uppercaseString]];
70}
71
72//?????????????
73//?????????????????е????
74//??????4??20λ????
75//???????????????10λ????С?????20λ?????????λ?????????????1???
76//1????????“???”????
77//2??“???”???????????????
78//3??“???”????4λ????????
79+(BOOL)verifyCardNumberWithSoldier:(NSString*)value
80{
81NSString*s1=@"^\d*$";
82NSString*s2=@"^.{1??}???\d{4??}$";
83//NSString*s3=@"^([A-Za-z0-9\u4e00-\u9fa5])*$";
84value=[valuestringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];
85if([VerifyRegexToolverifyText:valuewithRegex:s1]){
86NSString*s11=@"^\d{4??20}$";
87return[valueisMatchedByRegex:s11];
88}elseif([selflengthUsingChineseCharacterCountByTwo:value]>=10
89&&[selflengthUsingChineseCharacterCountByTwo:value]<=20){
90return[valueisMatchedByRegex:s2];
91}
92
93returnNO;
94}
95
96+(NSUInteger)lengthUsingChineseCharacterCountByTwo:(NSString*)string{
97NSUIntegercount=0;
98for(NSUIntegeri=0;i<string.length;++i){
99if([stringcharacterAtIndex:i]<256){
100count++;
101}else{
102count+=2;
103}
104}
105returncount;
106}
107
108//???????????????С??100??****????????в???????У?飬???????????????????
109+(BOOL)verifyIDCardHadAdult:(NSString*)card
110{
111NSString*birtday=[VerifyRegexToolgetIDCardBirthday:card];//****??**??**??
112//????****-**-**
113birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@"-"];
114birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@"-"];
115birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@""];
116birtday=[NSStringstringWithFormat:@"%@00:00"??birtday];
117NSDate*dateBirtday=[NSDatedateFromString:birtday];
118NSIntegeryear=[[NSDatedate]getIntervalTime:dateBirtdaywithDateType:DateTypeYear];//???????
119
120if(year>=18&&year<100){
121returnYES;
122}else{
123returnNO;
124}
125
126}
127
128//???????????????????????????number??????
129+(BOOL)verifyIDCardMoreThanPointDate:(NSString*)cardwithNumber:(NSInteger)numberwithAddTimeInterval:(NSTimeInterval)intervalwithDateType:(DateType)dateType{
130NSString*birtday=[VerifyRegexToolgetIDCardBirthday:card];//****??**??**??
131//????****-**-**
132birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@"-"];
133birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@"-"];
134birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@""];
135birtday=[NSStringstringWithFormat:@"%@00:00"??birtday];
136NSDate*dateBirtday=[NSDatedateFromString:birtday];
137NSDate*today=[NSDatedateFromStringWithoutTime:[[NSDatedate]strDate]];
138NSDate*pointDate=[todaydateByAddingTimeInterval:interval];
139
140//tempDate?number???????
141NSDate*tempDate=[pointDatedateAddNumber:-numberwithDateType:dateType];//???????
142if([dateBirtdayearlierDate:tempDate]==dateBirtday){//???????????????????tempdate???????
143returnYES;
144}else{
145returnNO;
146}
147}
148
149//?????????????????????С?????number??????
150+(BOOL)verifyIDCardLessThanPointDate:(NSString*)cardwithNumber:(NSInteger)numberwithAddTimeInterval:(NSTimeInterval)intervalwithDateType:(DateType)dateType
151{
152NSString*birtday=[VerifyRegexToolgetIDCardBirthday:card];//****??**??**??
153//????****-**-**
154birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@"-"];
155birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@"-"];
156birtday=[birtdaystringByReplacingOccurrencesOfString:@"??"withString:@""];
157birtday=[NSStringstringWithFormat:@"%@00:00"??birtday];
158NSDate*dateBirtday=[NSDatedateFromString:birtday];
159NSDate*today=[NSDatedateFromStringWithoutTime:[[NSDatedate]strDate]];
160NSDate*pointDate=[todaydateByAddingTimeInterval:interval];
161
162//tempDate?number???????
163NSDate*tempDate=[pointDatedateAddNumber:-numberwithDateType:dateType];//???????
164if([tempDateearlierDate:dateBirtday]==tempDate){//???????????????С??tempdate???????
165returnYES;
166}else{
167returnNO;
168}
169}
170
171//?????????????****????????в???????У?飬???????????????????
172+(NSString*)getIDCardBirthday:(NSString*)card{
173card=[cardstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];
174if([cardlength]!=18){
175returnnil;
176}
177NSString*birthady=[NSStringstringWithFormat:@"%@??%@??%@??"??[cardsubstringWithRange:NSMakeRange(6??4)]??[cardsubstringWithRange:NSMakeRange(10??2)]??[cardsubstringWithRange:NSMakeRange(12??2)]];
178returnbirthady;
179}
180
181//????????????1??0???****????????в???????У?飬???????????????????
182+(NSInteger)getIDCardSex:(NSString*)card{
183card=[cardstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];
184NSIntegerdefaultValue=0;
185if([cardlength]!=18){
186returndefaultValue;
187}
188NSIntegernumber=[[cardsubstringWithRange:NSMakeRange(16??1)]integerValue];
189if(number%2==0){//?????
190return0;
191}else{
192return1;
193}
194}
195
196@end
|
????????У??????????
1if(![VerifyRegexToolverifyIDCardNumber:self.IdentityCardNOTextfield.text]){//?????????????
2[selfshowMessageHUD:@"???????????????????"withTimeInterval:kShowMessageTime];
3return;
4}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
?????????????????HBase????????ú???????????????Rails????????????????Linux??????????????????????????????豸??????ò????????????????????????????Linux?????????????14??Linux?????7??????????????????? - ?洢?豸????????????????й???????Щ????????????????????Fuchsia??????б????iOS??????????????????? ???????????????????Linux????????AES??????????????α??????Linux??????????裺?????????????????????????????????????TmaxOS??????????iOS??Windows??????/WP???????????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????