无为清净楼资源网 Design By www.qnjia.com

验证规则:

1. Broadcast mac address (FF:FF:FF:FF::FF:FF:)

2. IPv4 & IPv6 multicast mac address

3. Numeric character

code list :

复制代码 代码如下:
function isValidMacAddress(address) { 
   var c = ''; 
   var i = 0, j = 0; 

    if ((address.toLowerCase() == 'ff:ff:ff:ff:ff:ff') || (address.toLowerCase() == '00:00:00:00:00:00')) { 
         alert('error'); 
         return false; 
   } 

   var addrParts = address.split(':'); 
   if (addrParts.length != 6) { 
       alert('error'); 
        return false; 
   } 
   for (i = 0; i < 6; i++){ 
        if (addrParts[i] == ''){ 
             alert('error'); 
             return false; 
        } 
   } 

   if (addrParts[i].length != 2) { 
        alert('error'); 
        return false; 
   } 
   for (j = 0; j < addrParts[i].length; j++) { 
        c = addrParts[i].toLowerCase().charAt(j); 
        if ((c >= '0' && c <= '9') || (c >= 'a' && c <='f')) { 
             continue; 
        } else { 
             alert('error'); 
             return false; 
        } 
   } 

   if ((parseInt(addrParts[0], 16) % 2) == 1) { 
        alert('error'); 
        return false; 
   } 

   return true; 

标签:
javascript,Mac,地址验证

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com