This question already has answers here:
How to check if URL is valid in Android
(12 answers)
Closed 8 years ago.
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
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
You can check it by using URLUtil .
if (URLUtil.isValidUrl(urlString)) {
// URL is valid
}
Hope it will be work for you.
Related
This question already has answers here:
How to set request encoding in Tomcat?
(2 answers)
Closed 6 years ago.
I'm calling a url like this:
http://localhost:8080/abc/income?content=%E0%B6%B8%E0%B6%9C%E0%B7%99+%E0%B6%B1%E0%B6%B8+%E0%B6%BD%E0%B6%9A%E0%B7%8A%E0%B6%B8%E0%B7%8F%E0%B6%BD%E0%B7%8A.&SOURCE_PRV=%20HTTP/1.1
and in the backend (tomcat) I'm decoding the string.
But I get the content as "??? ?? ???????" (several question marks).
How can I fix this?
The java.net.URI class can help; in the documentation of URL you find
Use one of the constructors with more than one argument, like:
URI uri = new URI(
"http",
"search.barnesandnoble.com",
"/booksearch/first book.pdf",
null);
URL url = uri.toURL();
//or String request = uri.toString();
This question already has answers here:
How to do URL decoding in Java?
(11 answers)
Closed 7 years ago.
I'm downloading a JSON from the Google Directions API. For the HTML_Instructions field, representing the actual instruction needed for navigation, here is the format:
"Head \u003cb\u003esoutheast\u003c/b\u003e on \u003cb\u003eMinor Ave\u003c/b\u003e toward \u003cb\u003eMadison St\u003c/b\u003e",
Is there a way to decode/remove the escape characters from the String that is downloaded in Java/an Android application.
Thanks for the help.
In Java use
String result = java.net.URLDecoder.decode(url, "UTF-8");
In JS use decodeURIComponent
document.write(decodeURIComponent("Head \u003cb\u003esoutheast\u003c/b\u003e on \u003cb\u003eMinor Ave\u003c/b\u003e toward \u003cb\u003eMadison St\u003c/b\u003e"))
This question already has answers here:
URLEncoder not able to translate space character
(19 answers)
Closed 9 years ago.
Hi Um quite new to Java and I want to encode Hello World it to Hello%20World . But when I use URLEncoder.encode it will encode the string as Hello+World and when we try to pass it via a Request to IIS it ll consider as a threat. How to encode as i mentioned ? Thank you in advance.
This only works for real URLs
URL u = new URL("Hello World");
String path = u.getPath();
This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 9 years ago.
I want to validate url started with http/https/www/ftp and checks for /\ slashes and checks for .com,.org etc at the end of URL using regular expression. Is there any regex patttern for URL validation?
This works:
Pattern p = Pattern.compile("(#)?(href=')?(HREF=')?(HREF=\")?(href=\")?(http://)?[a-zA-Z_0-9\\-]+(\\.\\w[a-zA-Z_0-9\\-]+)+(/[#&\\n\\-=?\\+\\%/\\.\\w]+)?");
Matcher m = p.matcher("your url here");
I am use the following code for that
String lRegex = "^(https?|ftp|file)://[-a-zA-Z0-9+&##/%?=~_|!:,.;]*[-a-zA-Z0-9+&##/%=~_|]";
btw a search in google and you would find the solution by yourself.
This question already has answers here:
How do I preserve the existing query string in a mod_rewrite rule
(2 answers)
Closed 8 years ago.
We are trying to redirect bin-ends2 to wines.jsp with a number of parameters passed over to the application server. Apache is stripping the parameters off and so the application server fdoes not know what yo put in the page. The Apache config is:
RewriteRule ^/wines/bin-ends2$ http://qa2:7025/wines/wines.jsp?Form=WinesSearch&type=binends [PT]
Does anyone know how to make this work?
You need to add QSA flag to your rule when you introduce new query string parameters and would like to preserve (better say, include) existing query string.
Your rule should be
RewriteRule ^/wines/bin-ends2$ http://qa2:7025/wines/wines.jsp?Form=WinesSearch&type=binends [QSA,PT]
Useful link: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa