Re: How do i valadate an email address?

From: Date: Thu, 27 Mar 2003 08:48:58 +0000
Subject: Re: How do i valadate an email address?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-141246@lists.php.net to get a copy of this message
Philip J. Newman wrote: > How would i check that an e-mail has the right parts in it. for example. > username @ domain . ext > Thanks > / Jim Bob Many people just check it like this: if (strpos($emailVar), '@') > 0) { echo 'Email is validated'; } else { echo 'Please supply a correct email address, don\'t you try no fancy stuff with me!'; } But this function from the pear class Validate, is more complete (can even check the domain): function validateEmail($email, $check_domain = false) { if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'. '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) { if ($check_domain && function_exists('checkdnsrr')) { list (, $domain) = explode('@', $email); if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) { return true; } return false; } return true; } return false; } Cheers!

« previous php.general (#141246) next »