Saturday 10 September 2016

Validate MAC Address in PHP

Simple snippet to validate MAC address in php. This functions receives mac address as input and returns a boolean value based on the check. If mac address is not valid function will return false or if valid it will return true.

function validateMacAddress($mac_address)
    return (bool)preg_match('/^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/', $mac_address);
}

No comments:

Post a Comment