Created
July 19, 2017 14:02
-
-
Save nuryslyrt/4daaed5992ccfd0ebc8022b545a219c9 to your computer and use it in GitHub Desktop.
Two options for url validating
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
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