Last active
May 28, 2019 23:10
-
-
Save hlev/eab73418ab20cdca3ff9 to your computer and use it in GitHub Desktop.
PHP regexp testing for valid MAC address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* To match aa:bb:cc:dd:ee:ff, aabbcddeeff, aa-bb-cc-dd-ee-ff formats in case-insensitive manner | |
*/ | |
$macAddress = '2a:3b:2c:1d:44:23'; | |
// 1 | |
echo preg_match('/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i', $macAddress); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment