You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
565 B
18 lines
565 B
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* URL验证工具类(工具层)
|
|
*/
|
|
public class UrlValidator {
|
|
// URL正则表达式(简化版,适配http/https/ftp)
|
|
private static final String URL_REGEX = "^(https?|ftp)://[a-zA-Z0-9.-]+(:\\d+)?(/.*)?$";
|
|
private static final Pattern URL_PATTERN = Pattern.compile(URL_REGEX);
|
|
|
|
// 验证URL格式
|
|
public static boolean isValidUrl(String url) {
|
|
if (url == null || url.trim().isEmpty()) {
|
|
return false;
|
|
}
|
|
return URL_PATTERN.matcher(url.trim()).matches();
|
|
}
|
|
}
|