How do I validate the format of a MAC address?

前端 未结 11 1477
逝去的感伤
逝去的感伤 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:39

    This works like a charm.

    def isMAC48Address(inputString):
        if inputString.count(":")!=5:
            return False
        for i in inputString.split(":"):
            for j in i:
                if j>"F" or (j<"A" and not j.isdigit()) or len(i)!=2:
                    return False
        return True 
    

提交回复
热议问题