javascript如何判断输入的url是否正确
人气:0
网页得来,原网页广告太多,影响心情
<html>
<head>
<title>检查是否为URL</title>
<script language="javascript">
function check(){
str = form1.txt.value;
str = str.match(/http:\/\/.+/);
if (str == null){
alert('你输入的URL无效');
return false;
}else{
alert("你输入的URL有效");
return true;
}
}
</script>
</head>
<body>
<form name="form1" onSubmit="return check()">
<input type="text" name="txt">
<input type="submit" value="检验">
</form>
</body>
</html>
复制代码 代码如下:
<html>
<head>
<title>检查是否为URL</title>
<script language="javascript">
function check(){
str = form1.txt.value;
str = str.match(/http:\/\/.+/);
if (str == null){
alert('你输入的URL无效');
return false;
}else{
alert("你输入的URL有效");
return true;
}
}
</script>
</head>
<body>
<form name="form1" onSubmit="return check()">
<input type="text" name="txt">
<input type="submit" value="检验">
</form>
</body>
</html>
加载全部内容