note 36538 added to function.eregi
| From: | c0p0n dot antisp at m dot myrealbox dot com | Date: | Tue, 14 Oct 2003 10:49:41 +0000 |
| Subject: | note 36538 added to function.eregi | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58564@lists.php.net to get a copy of this message | ||
a simple email validation function:
<?
function validate_email($string)
{
//checking that there is only one @, and that there are more than zero chars on both sides of the @
symbol
list( $name, $address) = split( "@", $string );
if ( (strlen($name) >= 1) && (strlen($address) >= 1))
{
//if the first @ position and the last @ position are on the same char,
//there is only one @ on the original email address (r00lez!)
$a = strrpos($string, '@');
$b = strpos($string, '@');
if ($a == $b)
{
//so, if the above is ok, let's check the address
list( $domain, $type) = split( ".", $address );
//it does NOT check if the second is a .com, .es or something like that. it only checks that there
is an
//apparently valid domain on $address (domain.type, or subdomain.domain). you can combine this
//function with others on this thread to complete that task...
if ( (strlen($domain) >= 1) && (strlen($type) >= 1) )
return(1); //all the above is correct, the email appears to have a valid syntax
}
else
return(0);
}
else
return(0);
}
?>
it does check that the email syntax is correct. it does not check if the domain exists, or the
domain type is correct. just to be merged with functions to do that.
----
Manual Page -- http://www.php.net/manual/en/function.eregi.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36538
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36538&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36538&report=yes
Search -- http://master.php.net/manage/user-notes.php