Home > Web Front-end > JS Tutorial > body text

JS method to verify IP, subnet mask, gateway and MAC_javascript skills

WBOY
Release: 2016-05-16 15:51:57
Original
1181 people have browsed it

The example in this article describes the JS method of verifying IP, subnet mask, gateway and MAC. Share it with everyone for your reference. The details are as follows:

<!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>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!