Android: Validate a URL string

0 Comments

Sometimes all we really need is to check if a URL is valid. You know, the standard "http(s)://domain.com/something/" pattern.

It took a while to find, but the API level 1 had it all along!

Just use URLUtil.isValidUrl() to test it.

1.// Validate URL
2.if (!URLUtil.isValidUrl(url)) {
3.  Toast.makeText(this, "Invalid URL specified", Toast.LENGTH_SHORT).show();
4.  return;
5.}

That's all folks!

 slidedog
Back to having fun!

Sources

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog