RE: [PHP] More Email ereg Validation

From: Date: Thu, 05 Apr 2001 00:46:05 +0000
Subject: RE: [PHP] More Email ereg Validation
Groups: php.general 
Request: Send a blank email to php-general+get-47147@lists.php.net to get a copy of this message
> This works great, except it doesn't accept the country code > domains (.au, etc). So I changed the number of characters to {2,3} at the > end of the regex: > ([a-z0-9_\.\-]+)@([a-z0-9\.-]+).([a-z]{2,3}) > > But then this works for the country code domains, but cuts > off a character of the 3 char domains because it matches the 2 characters as > well. So if I'm using the my@domain.com email address I end up with $1 = > "my", $2 = "domain" and $3 = "om" > > What do I do to catch both cases correctly? Function validEmail($emailaddress) { // Decides if the email address is valid. Checks syntax and DNS // records, for total smartass value. Returns "valid", "invalid-mx" // or "invalid-form". if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $emailaddress, $check)) { if ( checkdnsrr(substr(strstr($check[0], '@'), 1), "ANY") ) { return "valid"; } else { return "invalid-mx"; } } else { return "invalid-form"; } } If it gets through the first match with ".om", it won't get through the checkdnsrr(). Jason

« previous php.general (#47147) next »