@Test public void canadianPostalCodeTest() { assertTrue(CountryUtils.isCanadianPostalCodeValid("K1A 0B1")); assertTrue(CountryUtils.isCanadianPostalCodeValid("B1Z 0B9")); assertFalse(CountryUtils.isCanadianPostalCodeValid("K1A 0D1")); assertFalse(CountryUtils.isCanadianPostalCodeValid("94107")); assertFalse(CountryUtils.isCanadianPostalCodeValid("94107-1234")); assertFalse(CountryUtils.isCanadianPostalCodeValid("W1A 0B1")); assertFalse(CountryUtils.isCanadianPostalCodeValid("123")); assertFalse(CountryUtils.isCanadianPostalCodeValid("")); }
static boolean isCanadianPostalCodeValid(@NonNull String postalCode) { return Pattern.matches("^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$", postalCode); }
CountryUtils { static boolean isCanadianPostalCodeValid(@NonNull String postalCode) { return Pattern.matches("^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$", postalCode); } }
CountryUtils { static boolean isCanadianPostalCodeValid(@NonNull String postalCode) { return Pattern.matches("^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$", postalCode); }  }
CountryUtils { static boolean isCanadianPostalCodeValid(@NonNull String postalCode) { return Pattern.matches("^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$", postalCode); }   }
CountryUtils { static boolean isCanadianPostalCodeValid(@NonNull String postalCode) { return Pattern.matches("^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$", postalCode); }    }