@Test public void ukPostalCodeTest() { assertTrue(CountryUtils.isUKPostcodeValid("L1 8JQ")); assertTrue(CountryUtils.isUKPostcodeValid("GU16 7HF")); assertTrue(CountryUtils.isUKPostcodeValid("PO16 7GZ")); assertFalse(CountryUtils.isUKPostcodeValid("94107")); assertFalse(CountryUtils.isUKPostcodeValid("94107-1234")); assertFalse(CountryUtils.isUKPostcodeValid("!1A 0B1")); assertFalse(CountryUtils.isUKPostcodeValid("Z1A 0B1")); assertFalse(CountryUtils.isUKPostcodeValid("123")); }
static boolean isUKPostcodeValid(@NonNull String postcode) { return Pattern.matches("^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$", postcode); }
CountryUtils { static boolean isUKPostcodeValid(@NonNull String postcode) { return Pattern.matches("^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$", postcode); } }
CountryUtils { static boolean isUKPostcodeValid(@NonNull String postcode) { return Pattern.matches("^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$", postcode); }  }
CountryUtils { static boolean isUKPostcodeValid(@NonNull String postcode) { return Pattern.matches("^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$", postcode); }   }
CountryUtils { static boolean isUKPostcodeValid(@NonNull String postcode) { return Pattern.matches("^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$", postcode); }    }