This article mainly introduces two instances for judging and verifying MAC addresses in JS. If you need them, refer to method 1 below:
The Code 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 }/;
If (! Temp. test (document. mac. value ))
{
Return false;
}
Method 2:
The Code is as follows:
Function macFormCheck (mac)
{
Var macs = new Array ();
Macs = mac. split (":");
If (macs. length! = 6 ){
Alert ("the entered mac address format is incorrect. Please input it in the format of xx: xx (xx is a hexadecimal number )! "); // An 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 entered mac address format is incorrect. Please input it in the format of xx: xx (xx is a hexadecimal number )! ");
Return false;
}
If (temp <0 | temp> 255 ){
Alert ("the entered mac address format is incorrect. Please input it in the format of xx: xx (xx is a hexadecimal number )! ");
Return false;
}
}
Return true;
}