GWT java URL Validator
Does someone k开发者_如何学Pythonnows a function that validate if a url is valid or not purely in GWT java without using any JSNI
I am using this one (making use of regular expressions):
private RegExp urlValidator;
private RegExp urlPlusTldValidator;
public boolean isValidUrl(String url, boolean topLevelDomainRequired) {
if (urlValidator == null || urlPlusTldValidator == null) {
urlValidator = RegExp.compile("^((ftp|http|https)://[\\w@.\\-\\_]+(:\\d{1,5})?(/[\\w#!:.?+=&%@!\\_\\-/]+)*){1}$");
urlPlusTldValidator = RegExp.compile("^((ftp|http|https)://[\\w@.\\-\\_]+\\.[a-zA-Z]{2,}(:\\d{1,5})?(/[\\w#!:.?+=&%@!\\_\\-/]+)*){1}$");
}
return (topLevelDomainRequired ? urlPlusTldValidator : urlValidator).exec(url) != null;
}
org.apache.commons.validator.UrlValidator and static method isValid(String url) might be of help here.
You should use regular expression in GWT. Here is similar topics Regex in GWT to match URLs and Regular Expressions and GWT
精彩评论