JS验证IP,子网掩码,网关和MAC的方法
本文实例讲述了JS验证IP,子网掩码,网关和MAC的方法。分享给大家供大家参考。具体如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>测试IP</title> </head><script language="javascript"> <!--- function checkdata() { var reg = /^(/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(); return false; } //验证ip合法性 if(myform.ip.value.match(reg)) { // return true; } else { alert ("IP不合法"); myform.focus(); return false; } if(myform.zwym.value == "") { alert ("子网掩码不能为空"); myform.focus(); return false; } //验证子网掩码合法性 if(myform.zwym.value.match(reg)) { // return true; } else { alert ("子网掩码不合法"); myform.focus(); return false; } // if(myform.gateway.value == "") { alert ("网关不能为空"); myform.focus(); return false; } //验证网关合法性 if(myform.gateway.value.match(reg)) { // return true; } else { alert ("网关不合法"); myform.focus(); return false; } //MAC if(myform.mac.value == "") { alert ("MAC不能为空"); myform.focus(); return false; } //验证mac合法性 if(myform.mac.value.match(reg)) { // return true; } else { alert ("MAC不合法"); myform.focus(); return false; } } //--> </script><body> <form method="post" name="myform" onSubmit="return checkdata();"> <table width="708" height="253" border="1" id="table1" > <tr> <td width="186" height="53" ><div align="center">IP 地址:</div></td> <td width="506" height="53"> <input type="text" name="ip" size="15" maxlength="15" /> <font color="#FF0000">*</font>不能为空,必须填写</td> </tr> <tr> <td width="186" height="45" ><div align="center">子网掩码:</div></td> <td width="506" height="45" > <input type="text" name="zwym" size="15" maxlength="15" /> <font color="#FF0000">*</font>不能为空,必须填写</td> </tr> <tr> <td width="186" height="46" ><div align="center">网 关:</div></td> <td width="506" height="46"> <input type="text" name="gateway" size="15" maxlength="15" /> <font color="#FF0000">*</font>不能为空,必须填写</td> </tr> <tr> <td width="186" height="48"><div align="center">MAC地址:</div></td> <td width="506" height="48" > <input type="text" name="mac" size="15" maxlength="15" /> <font color="#FF0000">*</font>不能为空,必须填写</td> </tr> <tr><!---changeinfo(ip.value,zwym.value,mac.value,reboot)--> <!-- onClick="changeinfo(ip.value,zwym.value,gateway.value,mac.value)"----> <td height="47" colspan="2" align="center"><input type="submit" value="提交" /> <input type="reset" value="重置" /> </td> </tr> </table> </form> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。
相关推荐
ationwork 2020-06-16
DavidChao 2020-01-15
Wytheme 2020-01-19
Charliewolf 2020-01-03
farwang 2008-07-31
tianshijianbing 2008-07-06
dzwcom 2016-12-28
huangzonggui 2019-10-27
huhui0 2008-11-12
leodengzx 2019-10-26
Vi 2019-09-28
MD0 2019-09-26
康源留言 2019-09-11
seaocean 2017-06-12
lsn0LSN 2013-05-04
龍大笔记 2012-08-28
sjpeter 2017-09-08