Search code examples
javavalidationapache-commonsurl-validation

Validating URLs that don't have http


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?


Solution

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