Skip to content

Commit

Permalink
pod install lib
Browse files Browse the repository at this point in the history
pod install lib
  • Loading branch information
onexf committed Jul 8, 2016
1 parent 549be72 commit a0c16e0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
16 changes: 16 additions & 0 deletions VerifyTools.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Pod::Spec.new do |s|
s.name = ‘VerifyTools’
s.version = ‘0.0.1
s.summary = ‘A tool to verify cardNum.
s.description = <<-DESC
Verify cardNum,phoneNum,IDNum tool.
DESC
s.homepage = ‘https://github.com/onexf/VerifyTools'
s.license = ‘MIT’
s.author = { ‘onexf’ => ‘[email protected]’ }
s.ios.deployment_target = ‘8.0’
s.source = { :git => ‘https://github.com/onexf/VerifyTools.git', :tag => s.version }
s.source_files = ‘VerifyTools’, ‘VerifyTools/**/*.{h,m}
s.requires_arc = true
s.ios.frameworks = 'Foundation'
end
21 changes: 21 additions & 0 deletions VerifyTools/VerifyTools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// VerifyTools.h
// APP
//
// Created by pg on 16/7/8.
// Copyright © 2016年 person. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface VerifyTools : NSObject

/**
* 验证身份证是否正确
*
* @param value 传入的身份证
*
*/
+ (BOOL)verifyIDCardNumber:(NSString *)value;

@end
59 changes: 59 additions & 0 deletions VerifyTools/VerifyTools.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// VerifyTools.m
// APP
//
// Created by pg on 16/7/8.
// Copyright © 2016年 person. All rights reserved.
//

#import "VerifyTools.h"

@implementation VerifyTools

+ (BOOL)verifyIDCardNumber:(NSString *)value
{
if (value.length == 15) {
value = [self fifteenConvert_toEithteenWithValue:value];
}
value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([value length] != 18) {
return NO;
}
NSString *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])))";
NSString *leapMmdd = @"0229";
NSString *year = @"(19|20)[0-9]{2}";
NSString *leapYear = @"(19|20)(0[48]|[2468][048]|[13579][26])";
NSString *yearMmdd = [NSString stringWithFormat:@"%@%@", year, mmdd];
NSString *leapyearMmdd = [NSString stringWithFormat:@"%@%@", leapYear, leapMmdd];
NSString *yyyyMmdd = [NSString stringWithFormat:@"((%@)|(%@)|(%@))", yearMmdd, leapyearMmdd, @"20000229"];
NSString *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}";
NSString *regex = [NSString stringWithFormat:@"%@%@%@", area, yyyyMmdd , @"[0-9]{3}[0-9Xx]"];
NSPredicate *regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if (![regexTest evaluateWithObject:value]) {
return NO;
}
int summary = ([value substringWithRange:NSMakeRange(0,1)].intValue + [value substringWithRange:NSMakeRange(10,1)].intValue) *7 + ([value substringWithRange:NSMakeRange(1,1)].intValue + [value substringWithRange:NSMakeRange(11,1)].intValue) *9 + ([value substringWithRange:NSMakeRange(2,1)].intValue + [value substringWithRange:NSMakeRange(12,1)].intValue) *10 + ([value substringWithRange:NSMakeRange(3,1)].intValue + [value substringWithRange:NSMakeRange(13,1)].intValue) *5 + ([value substringWithRange:NSMakeRange(4,1)].intValue + [value substringWithRange:NSMakeRange(14,1)].intValue) *8 + ([value substringWithRange:NSMakeRange(5,1)].intValue + [value substringWithRange:NSMakeRange(15,1)].intValue) *4 + ([value substringWithRange:NSMakeRange(6,1)].intValue + [value substringWithRange:NSMakeRange(16,1)].intValue) *2 + [value substringWithRange:NSMakeRange(7,1)].intValue *1 + [value substringWithRange:NSMakeRange(8,1)].intValue *6 + [value substringWithRange:NSMakeRange(9,1)].intValue *3;
NSInteger remainder = summary % 11;
NSString *checkBit = @"";
NSString *checkString = @"10X98765432";
checkBit = [checkString substringWithRange:NSMakeRange(remainder,1)];// 判断校验位
return [checkBit isEqualToString:[[value substringWithRange:NSMakeRange(17,1)] uppercaseString]];
}

+ (NSString *)fifteenConvert_toEithteenWithValue:(NSString *)value
{
int W[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1};
NSMutableString *newValue = [NSMutableString stringWithString:value];
[newValue insertString:@"19" atIndex:6];
long p = 0;
for (int i = 0; i < 17; i ++) {
NSString *new = [newValue substringWithRange:NSMakeRange(i, 1)];
p += [new intValue]*W[i];
}
int q = p%11;
NSString *A[] = {@"1", @"0", @"X", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2"};
NSString *lastFigure = A[q];
[newValue insertString:lastFigure atIndex:newValue.length];
return newValue;
}
@end

0 comments on commit a0c16e0

Please sign in to comment.