Easily validate MAC addresses in your JavaScript projects using our MAC Address Regex JavaScript Validator. Designed for developers managing networks, device identification, and configuration tasks, this tool ensures MAC address inputs follow the correct format. Pair it with the JavaScript Regex Tester to experiment with custom patterns, or try the IP Address Regex JavaScript Validator for validating related network data. For frontend applications, use it alongside the Password Regex JavaScript Validator to secure user data with strict input checks.
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
Regular Expression - Documentation
What is MAC Address Regex?
A MAC (Media Access Control) address is a unique identifier assigned to network interfaces. It typically appears in the format 00:1A:2B:3C:4D:5E or 00-1A-2B-3C-4D-5E, using hexadecimal digits separated by colons or hyphens.
In JavaScript, we can use regular expressions (regex) to verify whether a string follows this structure before using it in networking, device identification, or access filtering.
MAC Address Regex Pattern
The commonly used regex to validate MAC addresses is:
This matches:
Six groups of two hexadecimal characters
Separated by either : or -
Case-insensitive (thanks to [A-Fa-f])
How to Validate MAC Address using Regex in JavaScript
Here’s a full JavaScript example:
Real-World Use Cases
Network configuration: Validate MAC addresses before storing or using them in router or server config tools.
Device management: Identify and verify devices in IoT ecosystems.
Access control: Allow or block specific MACs in security-sensitive systems.
Form input validation: Make sure users don’t enter invalid MAC formats in web applications.
Pro Tips
Always trim whitespace from input strings before validation.
Regex is for format checking, not legitimacy. A syntactically valid MAC address may still not exist.
Support both : and - formats if your application handles different sources.
Consider using Base64 Encoder for secure storage or transmission.
Use this in combination with Token Generator to assign unique device tokens post-validation.
JavaScript Metacharacters Used
^
: Anchors the regex at the start of the string.$
: Anchors the regex at the end of the string.[0-9A-Fa-f]
: Matches a single hexadecimal character (case-insensitive).{2}
: Quantifier – exactly 2 characters.[:-]
: Matches either ':' or '-'.{5}
: Quantifier – matches the group 5 times.(…)
: Capturing group.
Example Regex Inputs
"01:23:45:67:89:AB" → Valid
"01-23-45-67-89-AB" → Valid
"0123.4567.89AB" → Invalid
"G1:23:45:67:89:ZZ" → Invalid
Combine with These Tools
Use this MAC Address Validator alongside:
IP Address Regex JavaScript Validator: To validate full device network identity.
UUID Regex JavaScript Validator: To validate system-assigned unique IDs.
Base64 Decoder: Decode network data payloads after encryption.