Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isID(String s) { String strPattern = "^\\d{15}|^\\d{17}([0-9]|X|x)$"; Pattern p = Pattern.compile(strPattern); Matcher m = p.matcher(s); return m.matches(); } }