Greetings,

I saw this posted in this group a few days back:

function validEmail($email)
  { 
  if
(eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email))
    {
    return TRUE; 
    }
  else
    { 
    return FALSE; 
    } 
  }


I passed it onto a programmer friend of mine to help me get my head
around the regexp, which he did help me with, but then continued to
point out that this function would return FALSE for many many valid
email address', and I agree.  I had a look at the mail-header standard
(RFC-822), and almost ANYTHING is a valid email address...

The user (prefix of the @) can contain all sorts of special characters
(",',(,),etc) that weren't allowed for in the above regexp.

The domains (suffix of @) can basicaly be defined as "two or more groups
of a-z0-9, separated by a period (.)"  I *think* the above regexp does
this, but I'm no where near an expert.


So I'd rather have a regexp which loosly checks for a valid email,
rather than the very strict one above, which would appear to reject some
valid address'...

To me, checking for something like...

"anything"@"two or more groups of a-z0-9, separated by a ."

...is about as strict as it can get, based on my quick read of the spec.
 And I'd be pretty happy with a regexp which does this, but I have no
real clue how to write it.  Any help appreciated.


What would be great is a function which checks an email against the spec
-- has anyone built such a beast?


My friend also told me of a perl function which attempts to look-up the
email address via the DNS MX records... has anyone attempted this in
PHP???  Would there be any specific system requirements or limitations
(email forwarders, etc)????


I'm really interested in getting this right, and posting it as an FAQ or
article, rather than it kicking around in this group forever.


Thanks,

Justin French

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

Reply via email to