From effa38c0a0c6a65cf6cb028f0ac7f801438dde15 Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 12 Jan 2024 12:21:00 +0000 Subject: [PATCH] Added function validateMac() --- includes/functions.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/includes/functions.php b/includes/functions.php index 4d5c5b3c..9222c1b5 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -780,6 +780,23 @@ function validate_host($host) return preg_match('/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i', $host); } +/** + * Validates a MAC address + * + * @param string $mac + * @return bool + */ +function validateMac($mac) { + $macAddress = strtoupper(preg_replace('/[^a-fA-F0-9]/', '', $mac)); + if (strlen($macAddress) !== 12) { + return false; + } + if (!ctype_xdigit($macAddress)) { + return false; + } + return true; +} + // Gets night mode toggle value // @return boolean function getNightmode()