Pentru vlaidarea unui mac in PHP putem folosi:
Pentru adresele mac de tip UNIX (exemplu: 00:15:17:1D:73:5F)
$input_string = "00:15:17:1D:73:5F";
if (preg_match('/^[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}$/i',$input_string))
{
echo "Yes, the mac address is valid.";
} else
{
echo "No, the mac address is wrong";
}
Pentru adresele mac de tip WINDOWS (exemplu: 00-25-9c-4b-1e-2b)
$input_string = "00-25-9c-4b-1e-2b";
if (preg_match('/^[a-f0-9]{2}-[a-f0-9]{2}-[a-f0-9]{2}-[a-f0-9]{2}-[a-f0-9]{2}-[a-f0-9]{2}$/i',$input_string))
{
echo "Yes, the mac address is valid.";
} else
{
echo "No, the mac address is wrong";
}
Pentru adresele mac de tip Cisco (exemplu: 0018.f352.d31c)
$input_string = "0018.f352.d31c";
if (preg_match('/^[a-f0-9]{4}\.[a-f0-9]{4}\.[a-f0-9]{4}$/i',$input_string))
{
echo "Yes, the mac address is valid.";
} else
{
echo "No, the mac address is wrong";
}
Recent Comments