Mac地址验证的javascript代码_Javascript教程-查字典教程网
Mac地址验证的javascript代码
Mac地址验证的javascript代码
发布时间:2016-12-30 来源:查字典编辑
摘要:验证规则:1.Broadcastmacaddress(FF:FF:FF:FF::FF:FF:)2.IPv4&IPv6multicastmac...

验证规则:

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教程学习
    热门Javascript教程学习
    编程开发子分类