I allow user to input text string in my EditView. When I get Editview text, I want to validate if it is URL link or not? Can any one give Android code function? Thanks
Asked
Active
Viewed 5,898 times
1
-
Another is at http://stackoverflow.com/questions/5617749/how-to-validate-a-url-website-name-in-edittext-in-android – Pankaj Kumar Feb 25 '15 at 09:14
2 Answers
6
Use WEB_URL pattern in Patterns (android.util.Patterns) Class
Patterns.WEB_URL.matcher(inputTextForURLEdittext.toLowerCase()).matches();
It will return true if URL is valid and false if URL is invalid. For more info refer to this link http://developer.android.com/reference/android/util/Patterns.html

Amit K. Saha
- 5,871
- 2
- 27
- 35
0
You can check it by using URLUtil .
if (URLUtil.isValidUrl(urlString)) {
// URL is valid
}
Hope it will be work for you.

Arkar Aung
- 3,554
- 1
- 16
- 25