[Typo3-dev] Improvement of function validEmail($email)

Stefan Geith typo3dev at geithware.de
Mon Mar 8 17:31:11 CET 2004


Hi,

I had the idea to check for an existing MX-Record in DNS,
when validating an email-address. So only email-addresses
with a valid domainname would be ok.  Good idea ?

This could be included in class.t3lib_div.php with this
code:

<snip>
// class.t3lib_div.php : line 1083..1086
function validEmail($email)	{
   if (strstr($email,' '))	 return 0;
   if (ereg('^[A-Za-z0-9\._-]*[@][A-Za-z0-9\._-]*[\.].[A-Za-z0-9]*$',$email)) {
	$mailparts = explode ("@",$email,2);
	return (checkdnsrr ($mailparts[1], "MX") ? 1 : 0);
   } else {
	return (0);
   }
}
</snip>

changed from

<snip>
function validEmail($email)	{
   if (strstr($email,' '))	 return 0;
   return ereg('^[A-Za-z0-9\._-]*[@][A-Za-z0-9\._-]*[\.].[A-Za-z0-9]*$',$email) ? 1 : 0;
   }
</snip>

Stefan Geith









More information about the TYPO3-dev mailing list