I used "android.webkit.URLUtil" class for checking Url. But it has its own limitation.
I detected that it allow spaces in urls.
// if url contains http://
if(url.contains("http://")){
// Validate URL
if (!URLUtil.isValidUrl(url)) {
Toast.makeText(getActivity(),"Invalid URL specified", Toast.LENGTH_SHORT).show();
return;
}else{
// Your URL is Ready
}
}else{// if url does not contains http://
url = "http://" + url; //add it to yur url
// Validate URL
if (!URLUtil.isValidUrl(url)) {
Toast.makeText(getActivity(),"Invalid URL specified", Toast.LENGTH_SHORT).show();
return;
}else{
// Your link is ready
}
}
URLUtil at Android developer
Stack Over flow Answer how to validate a URL / website name in EditText in Android?