1

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

BSavaliya
  • 809
  • 1
  • 16
  • 26
Meas Serey
  • 57
  • 1
  • 4

2 Answers2

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