Regex for the MAC ID pattern to restrict FF:FF:FF:FF:FF:FF and leading 01-xx-xx-xx-xx-xx,

I tried to construct a working regex for the mentioned scenario but it’s not working.

  1. It should restrict the MAC IDs with leading "01" (01-xx-xx-xx-xx-xx). eg

01:AA:BB:05:31:01 <- Not valid.

21:51:51:31:01:AA <- Valid.

  1. It should restrict FF:FF:FF:FF:FF:FF full match.

What I have done so far is here.

^((?!01|FF|88|87|ff|00)[0-9a-fA-F]{2}([:-]|$)){6}$

6 thoughts on “Regex for the MAC ID pattern to restrict FF:FF:FF:FF:FF:FF and leading 01-xx-xx-xx-xx-xx,”

  1. You can try something like this:

    var macAddressAllowed = function(macAddr) {
      // regEX for valid MAC address
      var regExp = "^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$";
      var regex = new RegExp(regExp);
      var validMac = regex.test(macAddr);
      if(!validMac){
        return false;
      }else{
        macAddr = macAddr ? macAddr.toLowerCase() : '';
        var macAllowed = (macAddr === 'ff:ff:ff:ff:ff:ff' || macAddr.split(':')[0] === '01');
        return macAllowed ? false: true;
      }
     };
    
    Reply
  2. If you want to escape anything that begins with 01|FF|88|87|ff|00 use this

    pattern=/^(?=[^01|FF|88|87|ff|00])([0-9a-fA-F]{2}[:]){5}[0-9a-fA-F]{2}/gm
    

    if you want to escape beginning 01|88|87|00 and only a full patter FF use this one instead

    pattern=/^(?!01|88|87|00|FF:FF:FF:FF:FF:FF)([0-9a-fA-F]{2}[:]){5}[0-9a-fA-F]{2}/
    
    Reply

Leave a Comment