美文网首页
实名认证判断身份证和姓名是否合法

实名认证判断身份证和姓名是否合法

作者: 红烧肉都是我的 | 来源:发表于2016-08-24 15:56 被阅读0次

//判断姓名

-(void)checkName{

NSString * ptr = @"^[\u4E00-\u9FA5]*$";

NSPredicate * pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",ptr];

if (![pred evaluateWithObject:_realname.text]||_realname.text.length<2||_realname.text.length>6) {

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"请输入合法姓名!"] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:action];

[self presentViewController:alert animated:YES completion:nil];

}else{

[self upload];

}

}

//判断身份证号是否合法

-(void)checkIDcard

{

NSString *ptr = @"^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$";

NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",ptr];

if (_IDnum.text.length<=0) {

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"请输入18位有效身份证号"] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:action];

[self presentViewController:alert animated:YES completion:nil];

}else{

if ([pred evaluateWithObject:_IDnum.text]) {

if (_IDnum.text.length == 18) {

//将前17位加权因子保存在数组里

NSArray * idCardWiArray = @[@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3", @"7", @"9", @"10", @"5", @"8", @"4", @"2"];

//这是除以11后,可能产生的11位余数、验证码,也保存成数组

NSArray * idCardYArray = @[@"1", @"0", @"10", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2"];

//用来保存前17位各自乖以加权因子后的总和

NSInteger idCardWiSum = 0;

for(int i = 0;i < 17;i++)

{

NSInteger subStrIndex = [[_IDnum.text substringWithRange:NSMakeRange(i, 1)] integerValue];

NSInteger idCardWiIndex = [[idCardWiArray objectAtIndex:i] integerValue];

idCardWiSum+= subStrIndex * idCardWiIndex;

}

//计算出校验码所在数组的位置

NSInteger idCardMod=idCardWiSum%11;

//得到最后一位身份证号码

NSString * idCardLast= [_IDnum.text substringWithRange:NSMakeRange(17, 1)];

if (idCardMod == 2) {

if ([idCardLast isEqualToString:@"X"]) {

[self checkName];

}else{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"请输入18位有效身份证号"] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:action];

[self presentViewController:alert animated:YES completion:nil];

}

}else{

//用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码

if([idCardLast isEqualToString: [idCardYArray objectAtIndex:idCardMod]])

{

[self checkName];

}else{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"请输入18位有效身份证号"] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:action];

[self presentViewController:alert animated:YES completion:nil];

}

}

}else{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"请输入18位有效身份证号"] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:action];

[self presentViewController:alert animated:YES completion:nil];

}

}else{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"请输入18位有效身份证号"] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:action];

[self presentViewController:alert animated:YES completion:nil];

}

}

}

相关文章

  • 实名认证判断身份证和姓名是否合法

    //判断姓名 -(void)checkName{ NSString * ptr = @"^[\u4E00-\u9F...

  • 全局导航钩子

    //是否需要判断实名认证的路由

  • js验证真实姓名与身份证号/手机号

    js验证真实姓名与身份证号/手机号 Intro 最近的项目中用的需要调用实名认证的接口,实名认证接口价格相比短信而...

  • 实名认证方案

    实名认证有三种,一种身份证实名认证、手机号实名认证、银行卡实名认证。下面我们详述这几种认证方式的要素及接口。 1、...

  • 合作类

    目录: 1.数据平台的合作-------功能:身份证实名认证,手机号码实名认证,银行卡四要素实名认证。 2.银联数...

  • Shiro 高级

    自定义 Realm 『认证』和『授权』是 Shiro 要进行的两大操作: 认证,是判断用户的身份是否合法。类比于,...

  • 接口之家-身份证实名认证

    接口之家身份实名认证接口连接权威数据库,验证用户提供的身份证号码与姓名是否一致,是您系统网站、平台、app等产品校...

  • 七牛云图床配合markdown使用

    七牛官网 注册账号,并实名认证(一定要实名认证,不然云服务无法使用)实名认证需要身份证正反面图片,支付宝扫一扫

  • ZCF猪猪财富是什么?怎么做?靠谱吗?

    ZCF猪猪财富 团队对接微信: vip-16889988 一、注册实名认证全部四网统一 1、真实姓名 2、身份证...

  • 部分正则表达式

    部分正则表达式: 1.//TODO:判断身份证号是否合法 + (BOOL)validateIdentityCard...

网友评论

      本文标题:实名认证判断身份证和姓名是否合法

      本文链接:https://www.haomeiwen.com/subject/kpxosttx.html