JS验证IP,子网掩码,网关和MAC的方法
本文实例讲述了JS验证IP,子网掩码,网关和MAC的方法。分享给大家供大家参考。具体如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>测试IP</title>
</head><scriptlanguage="javascript">
<!---
functioncheckdata()
{
varreg=/^(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])(/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])){3}$/;
if(myform.ip.value=="")
{
alert("IP不能为空");
myform.focus();
returnfalse;
}
//验证ip合法性
if(myform.ip.value.match(reg))
{
//returntrue;
}
else
{
alert("IP不合法");
myform.focus();
returnfalse;
}
if(myform.zwym.value=="")
{
alert("子网掩码不能为空");
myform.focus();
returnfalse;
}
//验证子网掩码合法性
if(myform.zwym.value.match(reg))
{
//returntrue;
}
else
{
alert("子网掩码不合法");
myform.focus();
returnfalse;
}
//
if(myform.gateway.value=="")
{
alert("网关不能为空");
myform.focus();
returnfalse;
}
//验证网关合法性
if(myform.gateway.value.match(reg))
{
//returntrue;
}
else
{
alert("网关不合法");
myform.focus();
returnfalse;
}
//MAC
if(myform.mac.value=="")
{
alert("MAC不能为空");
myform.focus();
returnfalse;
}
//验证mac合法性
if(myform.mac.value.match(reg))
{
//returntrue;
}
else
{
alert("MAC不合法");
myform.focus();
returnfalse;
}
}
//-->
</script><body>
<formmethod="post"name="myform"onSubmit="returncheckdata();">
<tablewidth="708"height="253"border="1"id="table1">
<tr>
<tdwidth="186"height="53"><divalign="center">IP地址:</div></td>
<tdwidth="506"height="53">
<inputtype="text"name="ip"size="15"maxlength="15"/> <fontcolor="#FF0000">*</font>不能为空,必须填写</td>
</tr>
<tr>
<tdwidth="186"height="45"><divalign="center">子网掩码:</div></td>
<tdwidth="506"height="45"> <inputtype="text"name="zwym"size="15"maxlength="15"/> <fontcolor="#FF0000">*</font>不能为空,必须填写</td>
</tr>
<tr>
<tdwidth="186"height="46"><divalign="center">网关:</div></td>
<tdwidth="506"height="46">
<inputtype="text"name="gateway"size="15"maxlength="15"/> <fontcolor="#FF0000">*</font>不能为空,必须填写</td>
</tr>
<tr>
<tdwidth="186"height="48"><divalign="center">MAC地址:</div></td>
<tdwidth="506"height="48">
<inputtype="text"name="mac"size="15"maxlength="15"/> <fontcolor="#FF0000">*</font>不能为空,必须填写</td>
</tr>
<tr><!---changeinfo(ip.value,zwym.value,mac.value,reboot)-->
<!--onClick="changeinfo(ip.value,zwym.value,gateway.value,mac.value)"---->
<tdheight="47"colspan="2"align="center"><inputtype="submit"value="提交"/> <inputtype="reset"value="重置"/>
</td>
</tr>
</table>
</form>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。