It's very simple to use:
Boolean isValid = isUrl("http://androcode.es");
It's very simple to use:
Boolean isValid = isUrl("http://androcode.es");
private static boolean isUrl(String s) { | |
String regex = "^(https?://)?(([\\w!~*'().&=+$%-]+: )?[\\w!~*'().&=+$%-]+@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([\\w!~*'()-]+\\.)*([\\w^-][\\w-]{0,61})?[\\w]\\.[a-z]{2,6})(:[0-9]{1,4})?((/*)|(/+[\\w!~*'().;?:@&=+$,%#-]+)+/*)$"; | |
try { | |
Pattern patt = Pattern.compile(regex); | |
Matcher matcher = patt.matcher(s); | |
return matcher.matches(); | |
} catch (RuntimeException e) { | |
return false; | |
} | |
} |