IsoCodes\Mac::validate PHP Method

validate() public static method

Could be separated by hyphens or colons. Could be both lowercase or uppercase letters. Mixed upper/lower cases and hyphens/colons are not allowed.
public static validate ( string $mac ) : boolean
$mac string
return boolean
    public static function validate($mac)
    {
        $pattern = '/^(([a-f0-9]{2}-){5}[a-f0-9]{2}|([A-F0-9]{2}-){5}[A-Z0-9]{2}|([a-f0-9]{2}:){5}[a-z0-9]{2}|([A-F0-9]{2}:){5}[A-Z0-9]{2})$/';
        return boolval(preg_match($pattern, $mac));
    }

Usage Example

Beispiel #1
0
 /**
  * @dataProvider getInvalidMacAddresses
  *
  * @param string $mac
  */
 public function testInvalidMacAddress($mac)
 {
     $this->assertFalse(Mac::validate($mac));
 }