我不知道您所在国家/地区的确切邮政编码规则,但此代码段将帮助您入门:// define the pattern - should be defined as class field// instead of + you could use {3,5} to match min. 3, max. 5 characters - see regular expressions manualprivate static final Pattern PATTERN_ZIP = Pattern.compile("^[0-9A-Z]+[ \\-\\|]?[0-9A-Z]+$");String zip = "1A2-3B4C5";// Optional: let's make some text cleaningString cleanZip = zip.toUpperCase().trim();// Do the mat(c)hMatcher m = PATTERN_ZIP.matcher(cleanZip);if (m.find()) { System.out.println("Zip code correct");} else { System.out.println("Zip code incorrect");}