Apache UrlValidator for all scheme

java, url, url-validation

Solution

UrlValidator validator = new UrlValidator() {
    /** allow missing scheme. */
    @Override
    public boolean isValid(String value) {
        return super.isValid(value) || super.isValid("http://" + value);
    }
};

validator.validate("google.com");

Problem

I am using `org.apache.commons.validator.UrlValidator` for validating URL. It return true for http://www.google.com but false for www.google.com I want to allow www.google.com also. I applied ALLOW_ALL_SCHEMES as parameter but it is not working. How to customize UrlValidator so that it returns true for `www.google.com` and `http://localhost:8282/GFEReporting` also. Is there any way to customize this so it can take all schemes and no scheme? Please tell me. or is there any other way to do this? Thanks in advance...

Original source