Mac地址验证的javascript代码_javascript技巧
程序员文章站
2024-01-05 08:42:16
...
验证规则:
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 if (addrParts[i] == ''){
alert('error');
return false;
}
}
if (addrParts[i].length != 2) {
alert('error');
return false;
}
for (j = 0; j c = addrParts[i].toLowerCase().charAt(j);
if ((c >= '0' && c = 'a' && c continue;
} else {
alert('error');
return false;
}
}
if ((parseInt(addrParts[0], 16) % 2) == 1) {
alert('error');
return false;
}
return true;
}
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 if (addrParts[i] == ''){
alert('error');
return false;
}
}
if (addrParts[i].length != 2) {
alert('error');
return false;
}
for (j = 0; j c = addrParts[i].toLowerCase().charAt(j);
if ((c >= '0' && c = 'a' && c continue;
} else {
alert('error');
return false;
}
}
if ((parseInt(addrParts[0], 16) % 2) == 1) {
alert('error');
return false;
}
return true;
}
上一篇: 简单实现分页
推荐阅读
-
js 文本滚动效果的实例代码_javascript技巧
-
URL地址中的#符号使用说明_javascript技巧
-
Js实现双击鼠标自动滚动屏幕的示例代码_javascript技巧
-
按下回车键指向下一个位置的一个函数代码_javascript技巧
-
IE及firefox下获取及设置样式值的代码_javascript技巧
-
js按指定格式显示日期时间的样式代码_javascript技巧
-
javascript if 的简化代码_javascript技巧
-
php读取javascript设置的cookies的代码_php技巧
-
非常不错的功能强大代码简单的管理菜单美化版_javascript技巧
-
javascript 数字格式化输出的实现代码_javascript技巧