Aswin Balaji

Aswin Balaji

186 Sadasivam Nagar,Madipakkam,Chennai, TN 600091
Aswin Balaji

Validate a WEB URL in Android

September 5, 2015, by Aswin Balaji, category ANDROID
URLUtil.isHttpsUrl(String url), URLUtil.isHttpUrl(String url) andURLUtil.isValidUrl(String url) returns true in most of the cases.After reading few post on stackoverflow i got this very easy method for validation.

This solution uses regular expressions.Google Android SDK provides an interesting classPatterns(Added in API level 8). Which we can use to validate our WEB URL address.

Bellow is the example to validate Web-URL

EditText textField = (EditText) findViewById(;
String enteredUrl = textField.getText().toString();
if (Patterns.WEB_URL.matcher(enteredUrl).matches()) {
Toast.makeText(this, “URL is valid!”, Toast.LENGTH_LONG).show();
else {
Toast.makeText(this, “URL is invalid!”, Toast.LENGTH_LONG).show();