note 37570 rejected from function.ereg by pollita
| From: | pollita@php.net | Date: | Thu, 20 Nov 2003 00:39:33 +0000 |
| Subject: | note 37570 rejected from function.ereg by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-60652@lists.php.net to get a copy of this message | ||
Note Submitter: ok0n@poczta.fm
----
The easier way to validate IPv4 and ethernet hardware address (MAC):
function is_macaddress($mac)
{
if ( !eregi("^[0-9a-f]{2}(:[0-9a-f]{2}){5}$", $mac)) {
return FALSE;
}
return TRUE;
}
function is_ipv4address($addr)
{
if ( !ereg("^([0-9]{1,3}(\.[0-9]{1,3}){3})$", $addr)) {
return FALSE;
}
foreach (explode(".", $addr) as $a) {
if (($a < 0) || ($a > 255)) {
return FALSE;
}
}
return TRUE;
}
have fun,
okon.
PS. beware - in real world there are no such IPv4 addresses as 0.0.0.0 or 255.255.255.255 which
is_ipv4address() would validate successfuly!