public static boolean isValidDnsNameOrWildcard(String name) {
        return name.length() <= 255
                && (DNS_NAME.matcher(name).matches()
                || (name.startsWith("*.") && DNS_NAME.matcher(name.substring(2)).matches()));
    }
@Test
    public void testDnsNames()   {
        assertThat(IpAndDnsValidation.isValidDnsNameOrWildcard("example"), is(true));
        assertThat(IpAndDnsValidation.isValidDnsNameOrWildcard("example.com"), is(true));

        assertThat(IpAndDnsValidation.isValidDnsNameOrWildcard("example:com"), is(false));
        assertThat(IpAndDnsValidation.isValidDnsNameOrWildcard("veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongexample.com"), is(false));

        assertThat(IpAndDnsValidation.isValidDnsNameOrWildcard("example.com."), is(true));
        assertThat(IpAndDnsValidation.isValidDnsNameOrWildcard("example.com.."), is(false));
        assertThat(IpAndDnsValidation.isValidDnsNameOrWildcard("*.example.com."), is(true));
    }