Different MAC Addresses Regex

后端 未结 7 790
旧时难觅i
旧时难觅i 2021-01-06 08:30

What is the correct regular expression for matching MAC addresses ? I googled about that but, most of questions and answers are incomplete. They only provide a regular expre

7条回答
  •  不思量自难忘°
    2021-01-06 09:08

    MAC Address can be validated with the below code:

    private static final String PATTERN = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$";
        
    private static boolean validateMAC(String mac) {
            Pattern pattern = Pattern.compile(PATTERN);
            Matcher matcher = pattern.matcher(mac);
            return matcher.matches();
        }
    

提交回复
热议问题