How do I validate the format of a MAC address?

前端 未结 11 1424
逝去的感伤
逝去的感伤 2020-12-15 05:59

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

11条回答
  •  时光说笑
    2020-12-15 06:45

    pattern = "^(([0-9]{2}|[a-f]{2}|[0-9][a-f]|[a-f][0-9])\:){5}([0-9]{2}|[a-f]{2}|[0-9][a-f]|[a-f]|[0-9])$"
    
    valid_mac_check =re.search(pattern,"00:29:15:80:4E:4A",re.IGNORECASE)
    print(valid_mac_check.group())
    

提交回复
热议问题