Re: Validating Email addrs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 16, 2005 at 07:39:28AM -0000, George Pitcher wrote:
> I grabbed the following from a web-published article (sorry, can't remember
> where):

There a few things wrong with it as well.

> 
> function validate_email($email) {
> 	if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+(
> \.[a-zA-Z0-9_-] +)+$/" , $email)){
 
Problem #1
  - with those spaces in the expression i would assume it really
    needs to have the /x modifier, i would hardly thing that anyone
    will type:
    ' c  zirzow @ gmail .c '
  - it doesn't consider emails like foo@xxxxxxxxxx

I think there was a 300+ line regex to catch all cases, posted
earlier.


> 		list($username,$domain)=split('@',$email);
> 		if(!customCheckDnsrr($domain)){
> ...
> function customCheckDnsrr($host,$recType='') {
> 	if(!empty($host)) {
> 		if($recType=='') $recType="MX";
> 			exec("nslookup -type=$recType $host",$output);
> ...

Problem #2
 - an MX record isn't required to deliver email. Try a:
    nslookup -type=MX zirzow.dyndns.org then send an email to
    curt@xxxxxxxxxxxxxxxxx, i will get it.

> 			foreach($output as $line) {
> 			if(preg_match("/^$host/", $line)) {

Problem #3
 - MX hosts dont *have* to resolve to the same host it is doing
   mail for, it  generally does resolve that way, in most cases.
   
> 
> Never tested this, so can't comment on usefulness.

Uh.. well, i hope problems 1-3 should contribute to its (un)usefulness.

Curt.
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux