note 37570 added to function.ereg
| From: | ok0n at poczta dot fm | Date: | Wed, 19 Nov 2003 23:36:09 +0000 |
| Subject: | note 37570 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60645@lists.php.net to get a copy of this message | ||
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!
----
Manual Page -- http://www.php.net/manual/en/function.ereg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37570
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37570&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37570&report=yes
Search -- http://master.php.net/manage/user-notes.php