Method 1:
The code copy is as follows:
var temp = /[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}/;
if (!temp.test(document.mac.value))
{
return false;
}
Method 2:
The code copy is as follows:
function macFormCheck(mac)
{
var macs = new Array();
macs = mac.split(":");
if(macs.length != 6){
alert("The input mac address format is incorrect, please enter it in the form of xx:xx:xx:xx:xx:xx:xx:xx (xx is a hexadecimal number)!");// A online tutorial http://yige.org/js/
return false;
}
for (var s=0; s<6; s++) {
var temp = parseInt(macs[s],16);
if(isNaN(temp))
{
alert("The input mac address format is incorrect, please enter it in the form of xx:xx:xx:xx:xx:xx:xx:xx (xx is a hexadecimal number)!");
return false;
}
if(temp < 0 || temp > 255){
alert("The input mac address format is incorrect, please enter it in the form of xx:xx:xx:xx:xx:xx:xx:xx (xx is a hexadecimal number)!");
return false;
}
}
return true;
}