What\'s the best way to validate that an MAC address entered by the user?
The format is HH:HH:HH:HH:HH:HH
, where each H
is a hexadecimal ch
If you want to ensure that there is either '-' or ':' throughout but not both, you can use following in Python:
import re
def is_valid_macaddr802(value):
allowed = re.compile(r"""
(
^([0-9A-F]{2}[-]){5}([0-9A-F]{2})$
|^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$
)
""",
re.VERBOSE|re.IGNORECASE)
if allowed.match(value) is None:
return False
else:
return True