isMACAddress Function Documentation

The isMACAddress function checks if the input string is a valid MAC address. It returns true if the MAC address is valid and follows the supported formats, and false otherwise.

Import

The function can be imported using ES6 syntax from the "multiform-validator" package:

import { isMACAddress } from 'multiform-validator';

Alternatively, you can import the function using CommonJS syntax with require (Node.js):

const { isMACAddress } = require('multiform-validator');

Parameters

The function takes one parameter:

Examples

// Example 1 - Valid MAC addresses
const result1 = isMACAddress('001A2B3C4D5E'); // true
console.log(result1);

const result2 = isMACAddress('00:1A:2B:3C:4D:5E'); // true
console.log(result2);

const result3 = isMACAddress('00-1A-2B-3C-4D-5E'); // true
console.log(result3);

// Example 2 - Invalid MAC address
const result4 = isMACAddress('Hello'); // false
console.log(result4);

Notes

The function expects the input MAC address to be passed as a string. If the input is not a string, the function throws a TypeError. It removes all non-alphanumeric characters from the input string using a regular expression and checks if the resulting string has a valid length (exactly 12 characters). Then, it uses another regular expression to verify if the cleaned MAC address matches the supported pattern. The supported pattern is a 12-character string consisting of hexadecimal digits (0-9, A-F, a-f), with optional separators (":", "-") between pairs of hexadecimal digits.