Checking jquery / javascript MAC address

Possible duplicate:
What is a regular expression for a MAC address?

I would like to check the string to make sure that it is a valid MAC address.

Any ideas in jquery or javascript?

I have the following:

var mystring= '004F78935612'  - This type of MAC Address
var rege = /([0-9a-fA-F][0-9a-fA-F]){5}([0-9a-fA-F][0-9a-fA-F])/;
alert(rege.test(mystring));

But that is not all, for sure.

Those. My fabric box is a valid MAC address?!?

Thank!

+5
source share
1 answer

Taking the regular expression from this question , you would do it like this:

var mystring= 'Hello';

var regex = /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/;

alert(regex.test(mystring));

http://jsfiddle.net/s2WDq/

^, TWO hexidecimal digits [0-9A-F]{2}, [:-], (...){5}, [0-9A-F]{2} , , $.

: Pinch MAC-. , , ? :

/^([0-9A-F]{2}[:-]?){5}([0-9A-F]{2})$/
// question mark  ^ allows the colon or dash to be optional
+10

All Articles