Re: Don't use regular expressions to validate email addresses (was: I need some help with a regexp please)

2006-09-22 Thread Ant

Ben Finney wrote:
...
 The best advice I've seen when people ask How do I validate whether
 an email address is valid? was Try sending mail to it.

There are advantages to the regex method. It is faster than sending an
email and getting a positive or negative return code. The delay may not
be acceptable in many applications. Secondly, the false negatives found
by a reasonable regex will be few compared to the number you'd get if
the smtp server went down, or a remote relay was having problems
delivering the message etc etc.

From a business point of view, it is probably more important to reduce
the number of false negatives than to reduce the number of false
positives - every false negative is a potential loss of a customer.
False positives? Who cares really as long as they are paying ;-)

-- 
http://mail.python.org/mailman/listinfo/python-list


Don't use regular expressions to validate email addresses (was: I need some help with a regexp please)

2006-09-21 Thread Ben Finney
John Machin [EMAIL PROTECTED] writes:

 A little more is unfortunately not enough. The best advice you got was
 to use an existing e-mail address validator. The definition of a valid
 e-mail address is complicated. You may care to check out Mastering
 Regular Expressions by Jeffery Friedl. In the first edition, at least
 (I haven't looked at the 2nd), he works through assembling a 4700+ byte
 regex for validating e-mail addresses. Yes, that's 4KB.  It's the best
 advertisement for *not* using regexes for a task like that that I've
 ever seen.

The best advice I've seen when people ask How do I validate whether
an email address is valid? was Try sending mail to it.

It's both Pythonic, and truly the best way. If you actually want to
confirm, don't try to validate it statically; *use* the email address,
and check the result.  Send an email to that address, and don't use it
any further unless you get a reply saying yes, this is the right
address to use from the recipient.

The sending system's mail transport agent, not regular expressions,
determines which part is the domain to send the mail to.

The domain name system, not regular expressions, determines what
domains are valid, and what host should receive mail for that domain.

Most especially, the receiving mail system, not regular expressions,
determines what local-parts are valid.

-- 
 \   I believe in making the world safe for our children, but not |
  `\our children's children, because I don't think children should |
_o__)  be having sex.  -- Jack Handey |
Ben Finney

-- 
http://mail.python.org/mailman/listinfo/python-list