On Thu, Jan 18, 2007 at 01:40:36PM -0700, Don wrote:
I'm trying to get this line to validate an email address from a form and it
isn't working.
if (ereg("^.+@.+\..+$",$submittedEmail))
The book I'm referencing has this line
if (ereg("^.+@.+\\..+$",$submittedEmail))
Anyway.. I welcome any advice as long as it doesn't morph into a political
debate on ADA standards and poverty in Africa. :-)
Thanks
Don
Don:
I picked this up in my travels.
function validate_email($email)
{
// Create the syntactical validation regular expression
$regexp =
"^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("@",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}
return $valid;
}
$email = "johnny-rocket@xxxxxxxxxxx";
if (validate_email($email))
echo "Email is valid!";
else
echo "Email is invalid!";
hth's
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php