class UrlValidator {
public static void main (String[] args) {
check("http://google.com");
check("http://google.com?a=b#99");
check("http://google.com?a=b#99#sty");
check("http://www.google.com?a=1&b=2 / 3");
check("http://www.google.com?a=1&orderRate=orderRateUUID");
}
public static void check(String url) {
String Regex = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
Boolean matches = url.matches(Regex);
if(matches) {
System.out.println("URL (YES): " + url);
}
else {
System.out.println("URL (NOT): " + url);
}
}
}
No comments:
Post a Comment