验证身份证是否满18岁

由于项目中需要校验用户输入的身份证是否满18岁,且网上的方法鱼龙混杂,故自定义校验方法如下:

  • 第一种方法:
 //验证身份证是否成年这个方法中不做身份证校验,请确保传入的是正确身份证
 + (BOOL)verifyIDCardWithAdult:(NSString *)card{

//身份证:****年**月**日
     //年
     NSString *year = [card substringWithRange:NSMakeRange(6,4)];
     NSInteger  birthdayYear = [year integerValue];
     //月
     NSString *month = [card substringWithRange:NSMakeRange(10,2)];
     NSInteger  birthdayMonth = [month integerValue];
     //日
     NSString *day = [card substringWithRange:NSMakeRange(12,2)];
     NSInteger  birthdayDay = [day integerValue];


//获取当前时间,日期:
     NSDate *currentDate = [NSDate date];
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
     [dateFormatter setDateFormat:@"YYYY/MM/dd"];
     NSString *dateString = [dateFormatter stringFromDate:currentDate];
     NSRange range0 = [dateString rangeOfString:@"/"];
     //年
     NSString *year0 = [dateString substringToIndex:range0.location];
     NSInteger  nowYear = [year0 integerValue];
     //月
     NSString *month0 = [dateString substringWithRange:NSMakeRange(5, 2)];
     NSInteger  nowMonth = [month0 integerValue];
     //日
     NSString *day0 = [dateString substringWithRange:NSMakeRange(8, 2)];
     NSInteger  nowDay = [day0 integerValue];


//具体校验:
     //年
     if (nowYear - birthdayYear < 18){

         return false;
     }else if (nowYear - birthdayYear == 18){

         //月
         if (nowMonth < birthdayMonth){

             return false;


         }else if (nowMonth == birthdayMonth){

             //日
            if (nowDay < birthdayDay){

                return false;
            }
         }
     }
     return true;
}
  • 第二种方法:
+ (BOOL)verifyIDCardHadAdultII:(NSString *)card{

    //身份证:****年**月**日
    //年
    NSString *year = [card substringWithRange:NSMakeRange(6,4)];
    int  birthdayYear = [year intValue];
    birthdayYear+=18;

    //月日
    NSString *monthDay = [card substringWithRange:NSMakeRange(10,4)];
    int  birthdayMonth = [monthDay intValue];
    NSString *birthdayDay = [NSString stringWithFormat:@"%d%d",birthdayYear,birthdayMonth];

    //获取当前时间,日期:
    NSDate *currentDate = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYYMMdd"];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];

    //年
    NSString *year0 = [dateString substringWithRange:NSMakeRange(0, 4)];
    int  nowYear = [year0 intValue];
    //月日
    NSString *month0 = [dateString substringWithRange:NSMakeRange(4, 4)];
    int  nowMonth = [month0 intValue];
    NSString *current = [NSString stringWithFormat:@"%d%d",nowYear,nowMonth];


    //比较
    if([birthdayDay compare:current options:NSNumericSearch] == NSOrderedDescending){

        return false;
    }

    return true;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS自动拍摄身份证是指在iOS系统下使用相机应用,通过自动识别算法和拍摄功能,实现对身份证的快速、准确的拍摄。当用户使用该功能时,系统会自动识别身份证的边框,并根据识别结果自动调整相机的位置和角度,以确保身份证能够被完整地拍摄下来。用户只需要将身份证放在拍摄区域内,系统会自动对焦、曝光,并捕捉最佳的照片。 这种自动拍摄身份证的功能对于需要频繁进行身份证拍摄的场景非常有用,比如银行、机场、酒店等需要核实用户身份的场所。它可以减少工作人员的操作时间,提高效率,同时也减少了由于操作不当导致的照片模糊、角度不正等问题。而且由于自动拍摄的过程是由系统完成的,所以它具有一定的自动化和智能化的特点,可以降低用户的学习和使用成本。 要实现iOS自动拍摄身份证的功能,需要系统提供相应的接口和算法支持,并且相机应用需要和这些接口进行集成。在拍摄过程中,系统会实时分析图像,判断身份证的位置和倾斜角度,然后通过调整相机参数来优化拍摄效果。此外,系统还可以进行图像的后处理,对拍摄的照片进行自动裁剪、矫正、清晰化等处理,使得最终的拍摄结果更为精准和美观。 总而言之,iOS自动拍摄身份证的功能可以提高用户使用相机的便捷性和效率,是一种在特定场景下非常实用的技术。随着技术的不断进步,我们可以期待这个功能在未来得到更多的改进和应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值