Skip to content

Instantly share code, notes, and snippets.

@nuryslyrt
Created July 19, 2017 14:02
Show Gist options
  • Save nuryslyrt/4daaed5992ccfd0ebc8022b545a219c9 to your computer and use it in GitHub Desktop.
Save nuryslyrt/4daaed5992ccfd0ebc8022b545a219c9 to your computer and use it in GitHub Desktop.
Two options for url validating
/***
First Option:
--------------
***/
public static void main(String[] args) {
try{
String test = "http://netsparker.com";
System.out.println(test.matches("^(http|https)://.*$"));
} finally{
}
}
/***
Second Option:
--------------
***/
/**
Apache Commons UrlValidator class example:
http://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/routines/UrlValidator.html
**/
String[] schemes = {"http","https"}.
UrlValidator urlValidator = new UrlValidator(schemes);
if (urlValidator.isValid("ftp://foo.bar.com/")) {
System.out.println("URL is valid");
} else {
System.out.println("URL is invalid");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment