2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.silvercrestwifisocket.internal.utils;
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
19 * Utilitary static class to perform some validations.
21 * @author Jaime Vaz - Initial contribution
24 public final class ValidationUtils {
26 private ValidationUtils() {
27 // avoid instantiation.
30 public static final String MAC_PATTERN = "^([0-9A-Fa-f]{2}[:-]*){5}([0-9A-Fa-f]{2})$";
33 * Validates if one Mac address is valid.
35 * @param mac the mac, with or without :
36 * @return true if is valid.
38 public static boolean isMacValid(final String mac) {
39 Pattern pattern = Pattern.compile(ValidationUtils.MAC_PATTERN);
40 Matcher matcher = pattern.matcher(mac);
41 return matcher.matches();
45 * Validates if one Mac address is not valid.
47 * @param mac the mac, with or without :
48 * @return true if is not valid.
50 public static boolean isMacNotValid(final String macAddress) {
51 return !isMacValid(macAddress);