3

I'm trying to detect whether url is valid for using in WebView or not. There is an address bar in my WebView, so users can choose to navigate to another site or using keyword for search in google engine.

The problem is that all the solutions that I've found don't work properly. Cause if url is set without http, and I added it automatically, so it can considered valid url although it doesn't have any suffix.

Examples:

http://www.google.com - RETURN TRUE
google.com - RETURN TRUE (http will be added automatically)
http://google - RETURN FALSE (many validators consider this TRUE)
www.google - RETURN FALSE

So, what I'm trying to get is validator that verify string has the url structure, and if http is missing just add it. But if the string is not in url structure - go to another path (google engine for this example).

Thanks a lot.

RonZ
  • 743
  • 1
  • 11
  • 31
  • All of those strings are valid URLs. e.g `http://google` is valid URL and even maybe valid page to be navigated in some internal network. Nevertheless if you want to check if `hostname` is a globally resolvable domain, you must find get all currently known top-level domains and check if host name matches `/\.(all|possible|top|level|domains)$/` – Zbigniew Zagórski Jan 03 '17 at 10:05
  • Possible duplicate of [Trying to Validate URL Using JavaScript](http://stackoverflow.com/questions/1303872/trying-to-validate-url-using-javascript) – Justinas Jan 03 '17 at 10:08
  • Even if I can accept that `http://google` is valid url, how can I manage to separate urls and search values from my address bar. Cause if user write _things to do in London_, and http will be added - the validator consider this as valid url. Or in easier case, user write _Burger_ to search about burgers, I need a way to separate this things. – RonZ Jan 03 '17 at 10:22

0 Answers0