我需要使用jQuery 验证变量中的url ,但不能使用validate-plugin.有一个简单的方法吗?
该脚本应该检查提交的值是否为Url,但它不会这样做.我对正则表达式并不太熟悉,我的伙伴们为我做了这个旅行.
<script type="text/javascript">// <![CDATA[
window.onload=init;
function init(){
document.forms[0].onsubmit= function (){
var url= document.getElementById("url").value;
var desc= document.getElementById("description").value;
var regex=new RegExp("^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$");
var match=regex.test(url);
if(!match)
{
alert("The URL you entered is not valid");
return false;
}
if(desc.length<10)
{
alert("There must be at least 10 characters in the description");
return false;
}
};
}
// ]]></script>
Run Code Online (Sandbox Code Playgroud)