How to validate a URL / website name in EditText in Android?

As of Android API level 8 there is a WEB_URL pattern. Quoting the source, it "matches most part of RFC 3987". If you target a lower API level you could simply copy the pattern from the source and include it in your application.

I assume you know how to use patterns and matchers, so I'm not going into more details here Also the class URLUtil provides some useful methods, e. G: isHttpUrl()developer.android.com/reference/android/... isValidUrl()developer.android.com/reference/android/... The descriptions of the methods are not very elaborate, therefore you are probably best of looking at the source and figuring out which one fits your purpose best As for when to trigger the validation check, there are multiple possibilities: you could use the EditText callback functions onFocusChanged()http://developer.android.com/reference/android/widget/TextView.html#onFocusChanged%28boolean,%20int,%20android.graphics.Rect%29, or onTextChanged()http://developer.android.com/reference/android/widget/TextView.html#onTextChanged%28java.lang.CharSequence,%20int,%20int,%20int%29 or use a TextWatcher http://developer.android.com/reference/android/text/TextWatcher.html, which I think would be better I hope this helps, best regards Dimi EDIT: Since I'm a new user, I'm not allowed to post more than 2 links. Sorry for the inconvenience.

As of Android API level 8 there is a WEB_URL pattern. Quoting the source, it "matches most part of RFC 3987". If you target a lower API level you could simply copy the pattern from the source and include it in your application.

I assume you know how to use patterns and matchers, so I'm not going into more details here. Also the class URLUtil provides some useful methods, e. G: isHttpUrl()developer.android.com/reference/android/..., isValidUrl()developer.android.com/reference/android/... The descriptions of the methods are not very elaborate, therefore you are probably best of looking at the source and figuring out which one fits your purpose best.As for when to trigger the validation check, there are multiple possibilities: you could use the EditText callback functions onFocusChanged()http://developer.android.com/reference/android/widget/TextView.html#onFocusChanged%28boolean,%20int,%20android.graphics.Rect%29, or onTextChanged()http://developer.android.com/reference/android/widget/TextView.html#onTextChanged%28java.lang.CharSequence,%20int,%20int,%20int%29 or use a TextWatcher http://developer.android.com/reference/android/text/TextWatcher.html, which I think would be better.

I hope this helps, best regards, Dimi //EDIT: Since I'm a new user, I'm not allowed to post more than 2 links. Sorry for the inconvenience.

Thanks...i'll try this... – Preetam Jun 30 at 16:04.

URLUtil. IsValidUrl will work since it exists since api level 1.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions