I know this question has been asked but has anyone found a better URL validator library or tool other then the Apache commons-validator URLValidator, using a URLConnection object (super expensive), or a regex solution? I've tried implementing all of these and it seems the best one is the apache library but it still rejects valid URLs formatted such as:



I also tired to use google's Guava library but this was not great either. Any suggestions would be appreciated.

In the case of curiosity this is how I implemented the Apache library version:

public boolean validateUrl(final String url)
    final String[] urlSchemes = null;
    boolean isValid = false;

    final UrlValidator urlValidator = new UrlValidator(urlSchemes, UrlValidator.ALLOW_ALL_SCHEMES);
    final String urlText = url;
    if(isValid = urlValidator.isValid(urlText))
      //do nothing valid URL
       System.out.printf("URL %s is invalid.", urlText);

    return isValid;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.