Re: email validation string.

From: Date: Sat, 20 Jan 2007 13:53:32 +0000
Subject: Re: email validation string.
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-247439@lists.php.net to get a copy of this message
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@example.com"; 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

« previous php.general (#247439) next »