Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If 000.a83.b1c.08e is a valid MAC address then why is 123.123.123.123 not a valid address? Also how do we identify its 32 bit long or 48 bit long

What I have tried:

Also does this regex validate all kind of valid MAC address?
```
/^((([a-fA-F0-9][a-fA-F0-9]+[-]){5}|([a-fA-F0-9][a-fA-F0-9]+[:]){5})([a-fA-F0-9][a-fA-F0-9])$)|^([+-]?(?=\.\d|\d)(?:\d+)?(?:\.?\d*))(?:[eE]([+-]?\d+))?([a-zA-Z](([+-]?(?=\.\d|\d)(?:\d+)?(?:\.?\d*))(?:[eE]([+-]?\d+))?[a-zA-Z])+)$|(^([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]+[.]){2}([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]))$|(^([0-9]){15}$)/,
```
Posted
Updated 28-Oct-21 21:10pm

1 solution

Quote:
How to identify a valid MAC address?

By checking it has 6 groups of 2 hexadecimal digits (will 'validate' the form of the address, but not that it actually exists).
But, why? What is the need to validate a MAC address?

Quote:
If 000.a83.b1c.08e is a valid MAC address then why is 123.123.123.123 not a valid address?

000.a83.b1c.08e is not a well-formed MAC address.
123.123.123.123 is not a MAC address, it is an IP address.

Quote:
Also does this regex validate all kind of valid MAC address?

This regex does not validate any king of network address, nor MAC nor IP. It validates the hexadecimal representation of a decimal number.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900