Java tutorial
//package com.java2s; public class Main { public static final boolean isIdCard(String str) { if (isBlank(str)) { return false; } return str.matches("[0-9]{17}X") || str.matches("[0-9]{18}"); } private static boolean isBlank(String str) { if (str == null || str.matches("[ ]{0,}")) { return true; } return false; } }