Validating URLs that don't have http

544 Views Asked by At

I want to validate the website address user input in java side. I have used org.apache.commons.validator.routines.UrlValidator for this, but it needs URLs to start with http://, https://, or ftp://.

However, in my case i want to accept the address just starting with www., like www.stackoverflow.com. How can I do this?

1

There are 1 best solutions below

3
On BEST ANSWER

Create an URI object and check if getScheme() is empty or null. If so, preprend "http://"