身份证工具



import java.text.ParseException;
import java.util.Date;

import com.blankj.utilcode.util.LogUtils;

/**
 * 身份证工具
 */
public class ComposeUtil {

	/**
	 * 根据身份证号获取生日
	 * 
	 * @param composeStr
	 * @return
	 */
	public static Date getBirthdayByCompose(String composeStr) {

		String year = composeStr.substring(6, 10);
		String month = composeStr.substring(10, 12);
		String day = composeStr.substring(12, 14);

		LogUtils.e("ComposeUtil", year + "-" + month + "-" + day);
		try {
			return DateUtil.toDate(year + "-" + month + "-" + day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * Description: 检查身份证号码是否符合规则
	 * 
	 * @param idCode
	 *            String 身份证号码
	 * @return boolean 身份证号码正确,则返回true,否则返回false
	 */
	public static boolean isComposeNumber(String idCode) {
		int ai[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };
		boolean flag = false;
		if (idCode != null)
			switch (idCode.length()) {
			default:
				break;

			case 15: // '\017'
				flag = true;
				break;

			case 18: // '\022'
				int i = 0;
				for (int k = 0; k < 18; k++) {
					char c = idCode.charAt(k);
					int j;
					if (c == 'X' || c == 'x')
						j = 10;
					else if (c <= '9' || c >= '0')
						j = c - 48;
					else
						return flag;
					i += j * ai[k];
				}

				if (i % 11 == 1)
					flag = true;
				break;
			}
		return flag;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值