I'm trying to build a check that reliably evaluates whether the input ($f_username) is a MAC Address via Regex 'cause there are different Syntax it could take. Upon finding a match. this should be transferred to lowercase without deliminators.
The function works fine in matching and transforming most input, but will wrongly match longer input... e.g. 11-22-33-44-55-66-77-88 would be transferred to 11-22-33-44-55-66 and $match is set to true...
This should cause the function to go to the "else branch" as is is not an exact match of the pattern... however it contains a match... does anybody have an idea how to properly match this ?
Thanks for taking the time to read this and thanks in advance for any answers :)
function username_check($f_username) {
global $match;
if (preg_match_all("/([0-9a-fA-F]{2})[^0-9a-fA-F]?([0-9a-fA-F]{2})[^0-9a-fA-F]?([0-9a-fA-F]{2})[^0-9a-fA-F]?([0-9a-fA-F]{2})[^0-9a-fA-F]?([0-9a-fA-F]{2})[^0-9a-fA-F]?([0-9a-fA-F]{2})/", $f_username, $output, PREG_PATTERN_ORDER)) {
for ($i = 1; $i <= 6; $i++) {
$new_username .= strtolower($output[$i][0]);
}
$match = true;
$new_username = "'" . $new_username . "'"; //for later use in SQL-Query
} else {
$match = false;
}
return $new_username;
}