RE: [PHP] E-mail Validation
| From: | Paul Rydell | Date: | Tue, 12 Dec 2000 05:03:29 +0000 |
| Subject: | RE: [PHP] E-mail Validation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29802@lists.php.net to get a copy of this message | ||
Here is a method of checking for a valid e-mail address. It was stolen from
a script from a PERL script on Matt's Script Archive
(http://www.worldwidemart.com/scripts):
<?
if (preg_match ("/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/", $emailaddress) ||
preg_match
("/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/",
$emailaddress)) {
print "That is a valid e-mail.<BR>\n";
}
else {
print "Not a valid e-mail.<BR>\n";
}
?>
-----Original Message-----
From: Jason Murray [mailto:Jason.Murray@melbourneit.com.au]
Sent: Monday, December 11, 2000 8:31 PM
To: 'Bazko'; php-general@lists.php.net
Subject: RE: [PHP] E-mail Validation
> SSorry about all of the questions today,
> But I have made up a discussion page with php and want to put in email
> validation for users posts, can any one help me out on this.
We're using this on INWW:
Function validEmail($emailaddress)
{
// Decides if the email address is valid. Checks syntax and MX records,
// for total smartass value. Returns "valid", "invalid-mx" or
// "invalid-form".
// Validates the email address. I guess it works. *shrug*
if
(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$",
$emailaddress, $check))
{
if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp)
)
{ return "valid"; }
else
{ return "invalid-mx"; }
}
else
{
return "invalid-form";
}
}
This was culled from the notes on PHP's ereg page. There seems to be an
issue
with someone using a '+' sign in his username not passing the test. (Which
means
if anyone can suggest a modification to this eregi to allow a + through in
the
username, it'd be appreciated since I'm quite blonde when it come to this
... :))
Jason
--
Jason Murray
jasonm@melbourneit.com.au
Web Design Team, Melbourne IT
Fetch the comfy chair!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net