I grabbed the following from a web-published article (sorry, can't remember
where):

function validate_email($email) {
        if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] 
)+(
\.[a-zA-Z0-9_-] +)+$/" , $email)){
                list($username,$domain)=split('@',$email);
                if(!customCheckDnsrr($domain)){
                        $valid = 0;
                } else {
                        $valid = 1;
                }
        } else {
                $valid = 0;
        }
        return $valid;
}
function customCheckDnsrr($host,$recType='') {
        if(!empty($host)) {
                if($recType=='') $recType="MX";
                        exec("nslookup -type=$recType $host",$output);
                        foreach($output as $line) {
                        if(preg_match("/^$host/", $line)) {
                                return true;
                        }
                }
                return false;
        }
        return false;
}
I think this covers a windows server (like mine), but there is a shorter one
for Linux (which I'm moving to in the near future).

Never tested this, so can't comment on usefulness.

George


> -----Original Message-----
> From: Curt Zirzow [mailto:[EMAIL PROTECTED]
> Sent: 16 November 2005 4:04 am
> To: php-general@lists.php.net
> Subject: Re: [PHP] Validating Email addrs
>
>
> On Tue, Nov 15, 2005 at 11:16:15AM -0500, Leonard Burton wrote:
> > Hi All,
> >
> > I know that it is pretty darn impossible to come up with a regular
> > expression for validating emails.
> >
> > How do you all validated emails on form submission?
> >
> > Is it good just to do something like "/[EMAIL PROTECTED]/"  ?  That (or a
> > close derivative) should match that there is at least a @ and a . with
> > chars before and after each.  I will be sending an email to each new
> > registration with a confirmation link.
>
> Since you will be validating emails via a confirmation link, i'd
> probably suggest using the minimal testing, I dont think it is
> worth the headache.  If you become to strict on your regex you
> might eliminate something that is valid but the regex thought was
> invalid.
>
> At minimum [EMAIL PROTECTED] so to modify the regex a bit:
>
>   /[EMAIL PROTECTED],}$/
>
> Curt
> --
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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

Reply via email to