The MAC Address Regex Java Validator helps developers, testers, and network engineers validate MAC addresses using Java-compatible regex patterns. Whether you’re processing device logs, configuring routers, or cleaning up database entries, this tool ensures that each address follows standard MAC address formats.
You can also try these related Java validators:
[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 a MAC Address?
A MAC (Media Access Control) address is a unique hardware identifier assigned to network interfaces. A typical MAC address contains six groups of two hexadecimal digits, separated by either colons (:) or hyphens (-). Validating MAC addresses is essential in applications dealing with network configurations, IoT devices, and security monitoring.
Java Regex Pattern for MAC Address
Explanation:
^ and $: Anchors to ensure the pattern matches the entire string
([0-9A-Fa-f]{2}[:-]){5}: Matches five groups of two hex characters followed by either : or -
([0-9A-Fa-f]{2}): Final group of two hex characters
Accepts both formats: 01:23:45:67:89:AB and 01-23-45-67-89-AB
Java Code Example:
Valid & Invalid Examples
Valid:
00:1A:2B:3C:4D:5E
01-23-45-67-89-ab
FF:FF:FF:FF:FF:FF
Invalid:
001A2B3C4D5E (No separators)
ZZ:23:45:67:89:AB (Invalid characters)
01:23:45:67:89 (Too short)
01:23:45:67:89:AB:CD (Too long)
Pro Tips
Always sanitize user input before validating to avoid injection risks.
Use consistent separators (either : or -) in your backend systems for clean database storage.
MACs are hexadecimal; restrict input to 0–9 and A–F/a–f only.
Test edge cases like broadcast MAC (FF:FF:FF:FF:FF:FF) or multicast addresses.
Don’t confuse MAC addresses with IPs—MACs are static hardware-level identifiers.
The regex only checks format, not whether the MAC exists or is active.
Where It’s Used
Networking Software: Validate MACs in routers, switches, or DHCP tools
Inventory Systems: Ensure consistent MAC formats in device databases
IoT Applications: Track devices across hubs and ensure secure registration
Security Monitoring: Detect spoofed or malformed MAC addresses in logs
Combine with These Tools
IP Address Regex Java Validator: Validate IPs in the same network configuration.
UUID Regex Java Validator: Validate unique identifiers for connected devices.
Java Regex Tester: Experiment with variations of MAC address patterns.