开发者

GWT java URL Validator

开发者 https://www.devze.com 2023-01-31 09:05 出处:网络
Does someone k开发者_如何学Pythonnows a function that validate if a url is valid or not purely in GWT java without using any JSNII am using this one (making use of regular expressions):

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

0

精彩评论

暂无评论...
验证码 换一张
取 消