栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA 证件类型+证件号码校验(计算)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA 证件类型+证件号码校验(计算)

//定于返回对象   及返回对象定于
	List> retObjs = new ArrayList>();
	Map retObj = new HashMap();
	Map sex_Obj = new HashMap();
	Map birth_Obj = new HashMap();
	Map birth1_Obj = new HashMap();

	//列举所有已定于参数
	String  tempparam1 = param1;//证件类型
	String  tempparam2 = param2;//证件号码
   String ispd="error";
 	String isFanHui = "";
 	Boolean isContinue = true;
	Boolean isShow = true;
	String color = "red";


if (tempparam1.equals("1")){
 //系统数据类型 String java.lang.String;
  String regularexpression = "(^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)";

 boolean matches = tempparam2.matches(regularexpression);
 if (!matches) { 
   isContinue=false;
	isFanHui = "请输入正确的证件号码";
	ispd = "error";
 } else{
 if (tempparam2.length() == 18) {
   //判断身份证最后一位是否正确
     try {
         char[] charArray = tempparam2.toCharArray();
                    //前十七位加权因子
        int[] idCardWi = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
                    //这是除以11后,可能产生的11位余数对应的验证码
        String[] idCardY = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
        int sum = 0;
        for (int i = 0; i < idCardWi.length; i++) {
        	int current = Integer.parseInt(String.valueOf(charArray[i]));
       		int count = current * idCardWi[i];
        	sum += count;
         }
        char idCardLast = charArray[17];
        int idCardMod = sum % 11;
	    	SqlContext sqlContext = new SqlContext();

	   
  //身份证赋值生日
	   if(idCardY[idCardMod].toUpperCase().equals(String.valueOf(idCardLast).toUpperCase())) {
                        String bird1 = tempparam2.substring(6, 10) + '-' + tempparam2.substring(10, 12) + '-' + tempparam2.substring(12, 14);
	birth_Obj.put("message","");//提示信息 生日
	birth_Obj.put("value",bird1);
	birth_Obj.put("code","LCEMPLOYEE_BIRTHDAY");
	birth_Obj.put("type","changevalue");
	retObjs.add(birth_Obj);

	String bird2 = Integer.parseInt(tempparam2.substring(16, 17)) % 2 == 0 ? "2" : "1" ;
	sex_Obj.put("message","");//提示信息   性别
	sex_Obj.put("value",bird2);
	sex_Obj.put("code","LCEMPLOYEE_SEX");
	sex_Obj.put("type","changevalue");
	retObjs.add(sex_Obj);		  
   }else{
		isContinue=false;
		isFanHui = "身份证最后一位错误";
		ispd = "error";
		color = "red"; 
   }
 } catch (Exception e) {
                    e.printStackTrace();
    retObj.put("messageType",ispd);
    retObj.put("message",isFanHui);
    retObj.put("type","columnMessage");//"warnning"
                }
        }
 }
  
 	retObj.put("color",color);//显示颜色
	retObj.put("message",isFanHui);//提示信息
	retObj.put("isContinue",isContinue);//是否能继续执行按钮功能true/false
  	retObj.put("isShow",isShow);   
	retObj.put("columnCode","LCEMPLOYEE_V3_COLUMNMESSAGE");//提示的字段表名_字段名_COLUMNMESSAGE
	retObj.put("type","columnMessage");//type默认columnMessage,表示为字段下方的提示功能 
   retObjs.add(retObj);  
}
 return baseResponse.success().setData(retObjs);
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/602852.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号