Mac Address Regex Go Validator
Search...
⌘K
Mac Address Regex Go Validator
Search...
⌘K


Mac Address Regex Go Validator
Need to validate MAC addresses in Go? The Qodex MAC Address Regex Go Validator helps ensure your patterns match standard formats like 01:23:45:67:89:AB. Ideal for networking, device authentication, and input validation.
Pair it with the IP Regex Go Validator, UUID Generator, or API Key Generator for secure test setups. Add Username, Email, or Phone Number Generators to complete mock profiles with ease.
[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
MAC Address Regex Go Validator
A MAC address (Media Access Control address) is a unique identifier used to label devices on a network. Validating these addresses is critical in systems that track, authorize, or communicate with hardware components. The Qodex MAC Address Regex Go Validator helps developers and testers quickly confirm whether a string follows valid MAC formatting using Go’s regexp package.
What is a MAC Address Regex?
In Go, you can use regular expressions to match MAC address patterns. A typical MAC address looks like this:
01:23:45:67:89:AB or 01-23-45-67-89-AB
MAC addresses are composed of six groups of two hexadecimal digits separated by either colons or hyphens. The regex must ensure this format without allowing extra characters or missing segments.
Regex Pattern for MAC Addresses
Here’s the recommended Go regex for matching standard MAC addresses:
^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$
What it means:
^ – Start of string
([0-9a-fA-F]{2}[:-]){5} – Five pairs of hex digits followed by : or -
[0-9a-fA-F]{2} – Final pair without a separator
$ – End of string
This ensures the string is exactly 6 pairs and uses consistent separators.
Performance Considerations
When using a regular expression to validate a MAC address in Go, the process is generally quite efficient. The regex engine examines each character in the input string exactly once, leading to a time complexity of O(N), where N is the length of the MAC address string being checked.
Memory usage is minimal—the regular expression requires only a constant amount of additional space to perform the match (O(1) auxiliary space), independent of input length. This makes regex-based MAC address validation fast and lightweight, even when handling multiple inputs or integrating checks into API workflows.
How It Works
Input or paste your regex (or use the default).
Enter a test MAC address.
Instantly see whether it matches or fails.
Adjust your pattern as needed and validate again.
Example: Basic Validator
Use the Go Regex Tester to experiment with variations.
package main import ( "fmt" "regexp" ) func isValidMAC(mac string) bool { pattern := `^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$` macRegex := regexp.MustCompile(pattern) return macRegex.MatchString(mac) } func main() { fmt.Println(isValidMAC("00:1A:2B:3C:4D:5E")) // true fmt.Println(isValidMAC("00-1A-2B-3C-4D-5E")) // true fmt.Println(isValidMAC("001A.2B3C.4D5E")) // false fmt.Println(isValidMAC("01-23-45-67-89-AH")) // false fmt.Println(isValidMAC("01-23-45-67-AH")) // false }
Input: "00-1A-2B-3C-4D-5E"
Output: true
Explanation: This string matches the expected MAC address format with six groups of two hexadecimal digits separated by hyphens.
Input: "00:1A:2B:3C:4D:5E"
Output: true
Explanation: Colons are also valid separators, so this format passes.
Input: "001A.2B3C.4D5E"
Output: false
Explanation: Dots are not valid separators in this pattern, so it’s not recognized as a valid MAC address.
Input: "01-23-45-67-89-AH"
Output: false
Explanation: 'H'
is not a valid hexadecimal digit (should be 0–9, a–f, or A–F).
Input: "01-23-45-67-AH"
Output: false
Explanation: This string only has five groups instead of six.
By using a concise regular expression, this approach efficiently validates standard MAC address formats, ensuring only properly structured addresses return .
When Should You Use MAC Regex Validation?
Device registration systems: Validate MAC IDs during onboarding.
Network tools: Ensure clean, usable MAC input before connection setup.
IoT and embedded systems: Identify devices with consistency across logs.
Security software: Whitelist MACs using regex-based filtering.
Validating MAC Addresses in JavaScript
If you're looking to validate MAC addresses with JavaScript, a regular expression offers a concise and efficient solution. Whether you're parsing input for device onboarding or double-checking network configurations, here’s how you can tackle MAC address validation in your scripts.
Sample Regular Expression for MAC Addresses
A MAC address typically appears in formats like 01:23:45:67:89:AB
, 01-23-45-67-89-AB
, or 0123.4567.89AB
. To accommodate these, you can use the following regex pattern:
const macRegex = /^([0-9A-Fa-f]{2}([-:])){5}([0-9A-Fa-f]{2})$^([0-9A-Fa-f]{4}\.[0-9A-Fa-f]{4}\.[0-9A-Fa-f]{4})$/;
Validation Function in JavaScript
Here's a straightforward function to check if a string is a valid MAC address:
function isValidMacAddress(mac) { if (typeof mac !== 'string' !mac.length) return false; return macRegex.test(mac); }
Example Usage
You can use this function to validate different MAC address formats:
console.log(isValidMacAddress('01-23-45-67-89-AB')); // true console.log(isValidMacAddress('01:23:45:67:89:AB')); // true console.log(isValidMacAddress('0123.4567.89AB')); // true console.log(isValidMacAddress('01-23-45-67-89-AH')); // false console.log(isValidMacAddress('01-23-45-67-AH')); // false
With this approach, you can quickly validate user-submitted MAC addresses, enforce proper formatting in your apps, or build custom test utilities to streamline your QA process. And yes, you can easily extend this to integrate with your validation suites or device registration flows.
Validating MAC Addresses in Python
If you prefer Python over Go for your validation tasks, you can still harness the power of regular expressions to confirm proper MAC address formatting. This is handy if your stack is Python-rich but still demands robust input validation—think Flask APIs, CLI tools, or automation scripts.
Here's a straightforward Python example that checks for valid MAC addresses in both colon (:
) and hyphen (-
) formats:
import re def is_valid_mac(mac): pattern = r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" return bool(re.match(pattern, mac)) # Usage examples: print(is_valid_mac("01-23-45-67-89-AB")) # True print(is_valid_mac("01:23:45:67:89:AB")) # True print(is_valid_mac("0123.4567.89AB")) # False print(is_valid_mac("01-23-45-67-89-AH")) # False
What to note:
The regex mirrors the Go pattern for consistency—accepting only six groups of two hexadecimal digits (either uppercase or lowercase).
It strictly separates groups by either colons or hyphens (not a mix).
No support for the Cisco-style dotted notation (e.g.,
0123.4567.89AB
). If your system needs this, you'll want to extend the pattern.
For more advanced scenarios, you can enhance the regex or add checks for formatting edge cases based on your exact requirements. This compact approach keeps validation clean, fast, and in line with networking best practices.
How to Validate MAC Addresses in Java
Looking to validate MAC addresses in Java? You can use regular expressions to check for the standard formats—such as 01:23:45:67:89:AB
, 01-23-45-67-89-AB
, or even 0123.4567.89AB
. The key is to match the structure of these addresses using Java’s built-in regex capabilities.
Here’s a straightforward approach:
Choose a regex that covers common MAC address formats:
Hexadecimal pairs separated by colons (
:
) or hyphens (-
):01:23:45:67:89:AB
or01-23-45-67-89-AB
Three groups of four hexadecimal digits separated by dots (
.
):0123.4567.89AB
Sample Regex Pattern
String regex = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" + "^([0-9A-Fa-f]{4}\\.[0-9A-Fa-f]{4}\\.[0-9A-Fa-f]{4})$";
Implement a Validator Method:
import java.util.regex.Pattern; public static boolean isValidMAC(String input) { if (input == null) return false; String regex = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" + "^([0-9A-Fa-f]{4}\\.[0-9A-Fa-f]{4}\\.[0-9A-Fa-f]{4})$"; return Pattern.matches(regex, input); }
Usage Example:
System.out.println(isValidMAC("01:23:45:67:89:AB")); // true System.out.println(isValidMAC("01-23-45-67-89-AB")); // true System.out.println(isValidMAC("0123.4567.89AB")); // true System.out.println(isValidMAC("01-23-45-67-89-AH")); // false System.out.println(isValidMAC("not-a-mac")); // false
This method gives you a quick and flexible solution for validating MAC addresses in Java projects, whether you’re building network utilities or robust device management tools. Just copy the pattern above or adjust it as needed for your application.
How to Validate a MAC Address in C# Using Regex
Want to achieve the same MAC address validation in C#? No problem—it’s just as approachable, using .NET’s built-in Regex
class. The process involves crafting a regular expression that captures the correct pattern and checking whether the string matches. Here’s how you can implement it:
C# Code Example
Below is a simple C# function that checks if a string is a valid MAC address format, including support for both colon-separated, hyphen-separated, and even dot-separated Cisco-style addresses.
using System.Text.RegularExpressions; public static bool IsValidMacAddress(string input) { if (string.IsNullOrWhiteSpace(input)) return false; // Match 01:23:45:67:89:AB, 01-23-45-67-89-AB, or 0123.4567.89AB var pattern = @"^([0-9A-Fa-f]{2}([:-])){5}[0-9A-Fa-f]{2}$^([0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4}$"; return Regex.IsMatch(input, pattern
Example Usage
Console.WriteLine(IsValidMacAddress("01:23:45:67:89:AB")); // true Console.WriteLine(IsValidMacAddress("01-23-45-67-89-AB")); // true Console.WriteLine(IsValidMacAddress("0123.4567.89AB")); // true Console.WriteLine(IsValidMacAddress("01-23-45-67-89-AH")); // false Console.WriteLine(IsValidMacAddress("random-string")); // false
Quick Notes
The regex supports both common MAC address formats and the Cisco-style dot notation.
It checks for exactly six pairs (colon/hyphen formats) or three groups of four hex digits (dot format).
Any deviation—like invalid characters or missing segments—will fail the check.
If you need to perform MAC address validation elsewhere in your application, simply reuse this function and adjust the regex for additional formats as needed. This approach ensures your C# apps keep up with network standards, right alongside your Go and JavaScript test utilities.
Example: MAC Address Validation in C++
Need to validate MAC addresses in C++ instead of Go? You can use the C++ standard library’s <regex>
header to create a simple and robust validator. Here’s how you can check if a string is a valid MAC address using regular expressions in C++:
#include #include #include // Returns true if input is a valid MAC address format bool isValidMACAddress(const std::string& mac) { // Regex covers both colon and hyphen notations (e.g., 01:23:45:67:89:AB and 01-23-45-67-89-AB) // Adjust the pattern if you also wish to support dot-separated Cisco style (e.g., 0123.4567.89AB) std::regex macPattern("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"); return std::regex_match(mac, macPattern); } int main() { // Try out a few MAC address formats for validation std::cout << std::boolalpha; std::cout << isValidMACAddress("01-23-45-67-89-AB") << std::endl; // true std::cout << isValidMACAddress("01:23:45:67:89:AB") << std::endl; // true std::cout << isValidMACAddress("0123.4567.89AB") << std::endl; // false std::cout << isValidMACAddress("01-23-45-67-89-AH")<< std::endl; // false std::cout << isValidMACAddress("01-23-45-67-AH") << std::endl; // false return 0; }
How it works:
The pattern ensures that each segment contains two hexadecimal digits (
[0-9A-Fa-f]{2}
), with segments separated by either colons or hyphens.The function returns true only when the input matches the exact MAC address format—no stray characters, extra delimiters, or missing bytes.
Tip: If you need to accept dot-separated MACs (as seen in some Cisco hardware, e.g., 0123.4567.89AB
), the regex needs to be expanded. Otherwise, the standard pattern works for almost all general purposes.
Pro Tips for Better MAC Regex Validation
Use [0-9a-fA-F] to cover both upper and lowercase.
Stick to one separator style (colon or hyphen) within a regex to keep patterns strict.
Avoid patterns that allow trailing characters or incorrect segment lengths.
If comparing multiple device attributes, try pairing it with the IP Address Generator or UUID Generator.
Useful Metacharacters for MAC Regex
^
: Start of string$
: End of string[0-9a-fA-F]
: Any hex digit (case-insensitive){2}
: Exactly two characters[:-]
: Colon or hyphen separator{5}
: Repeat 5 times
You can copy this pattern directly into the Go Regex Tester to test your logic live.
Combine with These Tools
IP Address Generator – Simulate IP + MAC configurations
Username Generator – Pair MACs with user IDs in device dashboards
Password Generator – Secure MAC-tied device access
Phone Number Generator – Add mobile metadata to device records
Go Regex Tester – Debug any complex Go regex pattern quickly
Frequently asked questions
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
Mac Address Regex Go Validator
Search...
⌘K
Mac Address Regex Go Validator
Search...
⌘K


Mac Address Regex Go Validator
Mac Address Regex Go Validator
Need to validate MAC addresses in Go? The Qodex MAC Address Regex Go Validator helps ensure your patterns match standard formats like 01:23:45:67:89:AB. Ideal for networking, device authentication, and input validation.
Pair it with the IP Regex Go Validator, UUID Generator, or API Key Generator for secure test setups. Add Username, Email, or Phone Number Generators to complete mock profiles with ease.
[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
MAC Address Regex Go Validator
A MAC address (Media Access Control address) is a unique identifier used to label devices on a network. Validating these addresses is critical in systems that track, authorize, or communicate with hardware components. The Qodex MAC Address Regex Go Validator helps developers and testers quickly confirm whether a string follows valid MAC formatting using Go’s regexp package.
What is a MAC Address Regex?
In Go, you can use regular expressions to match MAC address patterns. A typical MAC address looks like this:
01:23:45:67:89:AB or 01-23-45-67-89-AB
MAC addresses are composed of six groups of two hexadecimal digits separated by either colons or hyphens. The regex must ensure this format without allowing extra characters or missing segments.
Regex Pattern for MAC Addresses
Here’s the recommended Go regex for matching standard MAC addresses:
^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$
What it means:
^ – Start of string
([0-9a-fA-F]{2}[:-]){5} – Five pairs of hex digits followed by : or -
[0-9a-fA-F]{2} – Final pair without a separator
$ – End of string
This ensures the string is exactly 6 pairs and uses consistent separators.
Performance Considerations
When using a regular expression to validate a MAC address in Go, the process is generally quite efficient. The regex engine examines each character in the input string exactly once, leading to a time complexity of O(N), where N is the length of the MAC address string being checked.
Memory usage is minimal—the regular expression requires only a constant amount of additional space to perform the match (O(1) auxiliary space), independent of input length. This makes regex-based MAC address validation fast and lightweight, even when handling multiple inputs or integrating checks into API workflows.
How It Works
Input or paste your regex (or use the default).
Enter a test MAC address.
Instantly see whether it matches or fails.
Adjust your pattern as needed and validate again.
Example: Basic Validator
Use the Go Regex Tester to experiment with variations.
package main import ( "fmt" "regexp" ) func isValidMAC(mac string) bool { pattern := `^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$` macRegex := regexp.MustCompile(pattern) return macRegex.MatchString(mac) } func main() { fmt.Println(isValidMAC("00:1A:2B:3C:4D:5E")) // true fmt.Println(isValidMAC("00-1A-2B-3C-4D-5E")) // true fmt.Println(isValidMAC("001A.2B3C.4D5E")) // false fmt.Println(isValidMAC("01-23-45-67-89-AH")) // false fmt.Println(isValidMAC("01-23-45-67-AH")) // false }
Input: "00-1A-2B-3C-4D-5E"
Output: true
Explanation: This string matches the expected MAC address format with six groups of two hexadecimal digits separated by hyphens.
Input: "00:1A:2B:3C:4D:5E"
Output: true
Explanation: Colons are also valid separators, so this format passes.
Input: "001A.2B3C.4D5E"
Output: false
Explanation: Dots are not valid separators in this pattern, so it’s not recognized as a valid MAC address.
Input: "01-23-45-67-89-AH"
Output: false
Explanation: 'H'
is not a valid hexadecimal digit (should be 0–9, a–f, or A–F).
Input: "01-23-45-67-AH"
Output: false
Explanation: This string only has five groups instead of six.
By using a concise regular expression, this approach efficiently validates standard MAC address formats, ensuring only properly structured addresses return .
When Should You Use MAC Regex Validation?
Device registration systems: Validate MAC IDs during onboarding.
Network tools: Ensure clean, usable MAC input before connection setup.
IoT and embedded systems: Identify devices with consistency across logs.
Security software: Whitelist MACs using regex-based filtering.
Validating MAC Addresses in JavaScript
If you're looking to validate MAC addresses with JavaScript, a regular expression offers a concise and efficient solution. Whether you're parsing input for device onboarding or double-checking network configurations, here’s how you can tackle MAC address validation in your scripts.
Sample Regular Expression for MAC Addresses
A MAC address typically appears in formats like 01:23:45:67:89:AB
, 01-23-45-67-89-AB
, or 0123.4567.89AB
. To accommodate these, you can use the following regex pattern:
const macRegex = /^([0-9A-Fa-f]{2}([-:])){5}([0-9A-Fa-f]{2})$^([0-9A-Fa-f]{4}\.[0-9A-Fa-f]{4}\.[0-9A-Fa-f]{4})$/;
Validation Function in JavaScript
Here's a straightforward function to check if a string is a valid MAC address:
function isValidMacAddress(mac) { if (typeof mac !== 'string' !mac.length) return false; return macRegex.test(mac); }
Example Usage
You can use this function to validate different MAC address formats:
console.log(isValidMacAddress('01-23-45-67-89-AB')); // true console.log(isValidMacAddress('01:23:45:67:89:AB')); // true console.log(isValidMacAddress('0123.4567.89AB')); // true console.log(isValidMacAddress('01-23-45-67-89-AH')); // false console.log(isValidMacAddress('01-23-45-67-AH')); // false
With this approach, you can quickly validate user-submitted MAC addresses, enforce proper formatting in your apps, or build custom test utilities to streamline your QA process. And yes, you can easily extend this to integrate with your validation suites or device registration flows.
Validating MAC Addresses in Python
If you prefer Python over Go for your validation tasks, you can still harness the power of regular expressions to confirm proper MAC address formatting. This is handy if your stack is Python-rich but still demands robust input validation—think Flask APIs, CLI tools, or automation scripts.
Here's a straightforward Python example that checks for valid MAC addresses in both colon (:
) and hyphen (-
) formats:
import re def is_valid_mac(mac): pattern = r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" return bool(re.match(pattern, mac)) # Usage examples: print(is_valid_mac("01-23-45-67-89-AB")) # True print(is_valid_mac("01:23:45:67:89:AB")) # True print(is_valid_mac("0123.4567.89AB")) # False print(is_valid_mac("01-23-45-67-89-AH")) # False
What to note:
The regex mirrors the Go pattern for consistency—accepting only six groups of two hexadecimal digits (either uppercase or lowercase).
It strictly separates groups by either colons or hyphens (not a mix).
No support for the Cisco-style dotted notation (e.g.,
0123.4567.89AB
). If your system needs this, you'll want to extend the pattern.
For more advanced scenarios, you can enhance the regex or add checks for formatting edge cases based on your exact requirements. This compact approach keeps validation clean, fast, and in line with networking best practices.
How to Validate MAC Addresses in Java
Looking to validate MAC addresses in Java? You can use regular expressions to check for the standard formats—such as 01:23:45:67:89:AB
, 01-23-45-67-89-AB
, or even 0123.4567.89AB
. The key is to match the structure of these addresses using Java’s built-in regex capabilities.
Here’s a straightforward approach:
Choose a regex that covers common MAC address formats:
Hexadecimal pairs separated by colons (
:
) or hyphens (-
):01:23:45:67:89:AB
or01-23-45-67-89-AB
Three groups of four hexadecimal digits separated by dots (
.
):0123.4567.89AB
Sample Regex Pattern
String regex = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" + "^([0-9A-Fa-f]{4}\\.[0-9A-Fa-f]{4}\\.[0-9A-Fa-f]{4})$";
Implement a Validator Method:
import java.util.regex.Pattern; public static boolean isValidMAC(String input) { if (input == null) return false; String regex = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" + "^([0-9A-Fa-f]{4}\\.[0-9A-Fa-f]{4}\\.[0-9A-Fa-f]{4})$"; return Pattern.matches(regex, input); }
Usage Example:
System.out.println(isValidMAC("01:23:45:67:89:AB")); // true System.out.println(isValidMAC("01-23-45-67-89-AB")); // true System.out.println(isValidMAC("0123.4567.89AB")); // true System.out.println(isValidMAC("01-23-45-67-89-AH")); // false System.out.println(isValidMAC("not-a-mac")); // false
This method gives you a quick and flexible solution for validating MAC addresses in Java projects, whether you’re building network utilities or robust device management tools. Just copy the pattern above or adjust it as needed for your application.
How to Validate a MAC Address in C# Using Regex
Want to achieve the same MAC address validation in C#? No problem—it’s just as approachable, using .NET’s built-in Regex
class. The process involves crafting a regular expression that captures the correct pattern and checking whether the string matches. Here’s how you can implement it:
C# Code Example
Below is a simple C# function that checks if a string is a valid MAC address format, including support for both colon-separated, hyphen-separated, and even dot-separated Cisco-style addresses.
using System.Text.RegularExpressions; public static bool IsValidMacAddress(string input) { if (string.IsNullOrWhiteSpace(input)) return false; // Match 01:23:45:67:89:AB, 01-23-45-67-89-AB, or 0123.4567.89AB var pattern = @"^([0-9A-Fa-f]{2}([:-])){5}[0-9A-Fa-f]{2}$^([0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4}$"; return Regex.IsMatch(input, pattern
Example Usage
Console.WriteLine(IsValidMacAddress("01:23:45:67:89:AB")); // true Console.WriteLine(IsValidMacAddress("01-23-45-67-89-AB")); // true Console.WriteLine(IsValidMacAddress("0123.4567.89AB")); // true Console.WriteLine(IsValidMacAddress("01-23-45-67-89-AH")); // false Console.WriteLine(IsValidMacAddress("random-string")); // false
Quick Notes
The regex supports both common MAC address formats and the Cisco-style dot notation.
It checks for exactly six pairs (colon/hyphen formats) or three groups of four hex digits (dot format).
Any deviation—like invalid characters or missing segments—will fail the check.
If you need to perform MAC address validation elsewhere in your application, simply reuse this function and adjust the regex for additional formats as needed. This approach ensures your C# apps keep up with network standards, right alongside your Go and JavaScript test utilities.
Example: MAC Address Validation in C++
Need to validate MAC addresses in C++ instead of Go? You can use the C++ standard library’s <regex>
header to create a simple and robust validator. Here’s how you can check if a string is a valid MAC address using regular expressions in C++:
#include #include #include // Returns true if input is a valid MAC address format bool isValidMACAddress(const std::string& mac) { // Regex covers both colon and hyphen notations (e.g., 01:23:45:67:89:AB and 01-23-45-67-89-AB) // Adjust the pattern if you also wish to support dot-separated Cisco style (e.g., 0123.4567.89AB) std::regex macPattern("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"); return std::regex_match(mac, macPattern); } int main() { // Try out a few MAC address formats for validation std::cout << std::boolalpha; std::cout << isValidMACAddress("01-23-45-67-89-AB") << std::endl; // true std::cout << isValidMACAddress("01:23:45:67:89:AB") << std::endl; // true std::cout << isValidMACAddress("0123.4567.89AB") << std::endl; // false std::cout << isValidMACAddress("01-23-45-67-89-AH")<< std::endl; // false std::cout << isValidMACAddress("01-23-45-67-AH") << std::endl; // false return 0; }
How it works:
The pattern ensures that each segment contains two hexadecimal digits (
[0-9A-Fa-f]{2}
), with segments separated by either colons or hyphens.The function returns true only when the input matches the exact MAC address format—no stray characters, extra delimiters, or missing bytes.
Tip: If you need to accept dot-separated MACs (as seen in some Cisco hardware, e.g., 0123.4567.89AB
), the regex needs to be expanded. Otherwise, the standard pattern works for almost all general purposes.
Pro Tips for Better MAC Regex Validation
Use [0-9a-fA-F] to cover both upper and lowercase.
Stick to one separator style (colon or hyphen) within a regex to keep patterns strict.
Avoid patterns that allow trailing characters or incorrect segment lengths.
If comparing multiple device attributes, try pairing it with the IP Address Generator or UUID Generator.
Useful Metacharacters for MAC Regex
^
: Start of string$
: End of string[0-9a-fA-F]
: Any hex digit (case-insensitive){2}
: Exactly two characters[:-]
: Colon or hyphen separator{5}
: Repeat 5 times
You can copy this pattern directly into the Go Regex Tester to test your logic live.
Combine with These Tools
IP Address Generator – Simulate IP + MAC configurations
Username Generator – Pair MACs with user IDs in device dashboards
Password Generator – Secure MAC-tied device access
Phone Number Generator – Add mobile metadata to device records
Go Regex Tester – Debug any complex Go regex pattern quickly
Frequently asked questions
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex