Android: Validate a URL string

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

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

Just use URLUtil.isValidUrl() to test it.

// Validate URL
if (!URLUtil.isValidUrl(url)) {
Toast.makeText(this, "Invalid URL specified", Toast.LENGTH_SHORT).show();

That's all folks!

Back to having fun!


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