Android 判断当前身份证格式是否正确

传入字符串 判断当前身份证号码是否正确

// 身份证验证
	public static boolean isSFZ(String str) {
		try {
			if (str.length() != 18) {
				return false;
			}
			String[] array = { "1", "0", "x", "9", "8", "7", "6", "5", "4",
					"3", "2" };
			int sum = 0;
			int count = 17;
			for (int i = 0; i < str.length() - 1; i++) {
				int a = Integer.parseInt("" + str.charAt(i));
				sum += a * Math.pow(2, count);
				count--;
			}
			return (str.charAt(str.length() - 1) + "")
					.equalsIgnoreCase(array[sum % 11]);
		} catch (Exception e) {
			return false;
		}
	}

猜你喜欢

转载自blog.csdn.net/qq_28643195/article/details/107428588
今日推荐