`

身份证号码验证

    博客分类:
  • j2ee
阅读更多
// 验证身份证号是否合法
	private static boolean isCardNo(String card) {
		try {
			// 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
			String regex = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";
			Pattern p = Pattern.compile(regex);
			Matcher m = p.matcher(card);
			if (m.find()) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;

	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics