/** * 判斷是否含有特殊字符 * * @param str * @return true為包含,false為不包含 */ public static boolean isSpecialChar(String str) { String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\r|\t"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(str); return m.find(); } /** * 判斷是否以0開頭 * * @param code * @return true為合法,false為不合法 */ public static boolean isZeroBefore(String code){ String regex="^0\\d*$"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(code); return m.matches(); }
