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...
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");
private boolean isValidUrl(String value) {
return UrlValidator.getInstance().isValid(value)
|| UrlValidator.getInstance().isValid("http://" + value);
}
This is simplified @Sergey's answer (without extending the UrlValidator() class).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With