Regex for MAC Address
Validates MAC addresses in colon or hyphen-separated format.
Pattern
/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/i Live Tester
Enter a string to test
Examples
The i flag makes the pattern case-insensitive.
✓ 00:1A:2B:3C:4D:5E
✓ AA-BB-CC-DD-EE-FF
✓ 01:23:45:67:89:ab
✗ 00:1A:2B:3C:4D
✗ GG:HH:II:JJ:KK:LL
✗ 001A2B3C4D5E
Pattern Breakdown
([0-9A-Fa-f]{2}[:-]){5} — five hex pairs with separator
([0-9A-Fa-f]{2})$ — final pair
Code Snippets
Javascript
/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/i.test("00:1A:2B:3C:4D:5E"); // true Python
bool(re.match(r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", "00:1A:2B:3C:4D:5E", re.I)) # True Php
preg_match('/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/i', "00:1A:2B:3C:4D:5E"); // 1 Related Patterns
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Frequently Asked Questions
What is the regex for MAC Address?▾
The regex pattern for MAC Address is /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/i. Validates MAC addresses in colon or hyphen-separated format.
How do I use the MAC Address regex in JavaScript?▾
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the MAC Address pattern match?▾
It matches strings like 00:1A:2B:3C:4D:5E; it rejects strings like 00:1A:2B:3C:4D. See the Examples section above for the full list of matching and non-matching cases.