JS验证
- JScript code
function isValidUrl(obj) { // alert('22'); ///^http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$/ reg =@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"; alert(obj); if (!reg.test(obj)) { alert("Error"); } else { alert("Error"); } } 这需要验证URL地址,但现在使用这种写法,验证不了,reg =@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?" 这种写法有问题 吗?
应该如何 实现 。
[解决办法]
- JScript code
function isURL() { var strRegex = "^((https|http|ftp|rtsp|mms)://)?[a-z0-9A-Z]{3}\.[a-z0-9A-Z][a-z0-9A-Z]{0,61}?[a-z0-9A-Z]\.com|net|cn|cc (:s[0-9]{1-4})?/$"; var re = new RegExp(strRegex); if (re.test(document.getElementById("<%=txtServerIP.ClientID %>").value)) { alert("成功"); return true; } else { alert("失败"); return false; } }