const VALID = true; const INVALID = false; class validation { static mac_addr(addr) { const VALID_MAC_CHARS = "0123456789abcdefABCDEF"; if (addr.length !== 17) { return INVALID; } const COLON_START_IDX = 2; const COLON_STEP = 3; for (let idx = COLON_START_IDX; idx < addr.length; idx += COLON_STEP) { if (addr[idx] != ":") { return INVALID; } } const mac_sections = addr.split(":"); if (mac_sections.length !== 6) { return INVALID; } for (const mac_byte of mac_sections) { if (mac_byte.length !== 2) { return INVALID; } for (const char of mac_byte) { if (!VALID_MAC_CHARS.includes(char)) { return INVALID; } } } return VALID; } }