Search code examples
javaurl-validation

Why UrlValidator do not work for some of my Urls?


String[] schemes = {"http","https"};
UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_ALL_SCHEMES);
System.out.println(urlValidator.isValid(myUrl));

the following URL says, invalid. Any one know why is that. the localnet is a localnetwork. But this works for any other public network (it seems).

http://aunt.localnet/songs/barnbeat.ogg

Solution

  • As I thought, its failing on the top level;

    String topLevel = domainSegment[segmentCount - 1];
    if (topLevel.length() < 2 || topLevel.length() > 4) {
      return false;
    }
    

    your top level is localnet.