判断Http地址
public class Test {
static void test(String str) {
if (Pattern.compile("^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\\\\\\\\/])+$")
.matcher(str).find()) {
System.out.println(true);
}else {
System.out.println(false);
}
}
public static void main(String[] args) {
test("https://www.baidu.com");
test("http://www.baidu.com?param1=abc¶m2=111¶m3=222");
test("http://www.baidu.com?param1=abc¶m2=222*");
test("http://www.baidu.com?param1=abc¶m2=123-456")
test("http://www.baidu.com?param1=abc¶m2=123-456*");
}
}
输出:
true
true
false
true
false
邮箱验证
^[a-zA-Z0-9_.\-]{2,}@[a-zA-Z0-9_\-]{2,}(\.[a-zA-Z0-9_\-]+){1,2}$