Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Email Validation, Round 2

by legLess (Hermit)
on Aug 24, 2001 at 22:56 UTC ( [id://107666]=note: print w/replies, xml ) Need Help??


in reply to Email Validation, Round 2

IMHO the O'Reilly Mouse book (CGI Programming with Perl, 2nd edition) has a very good take on this. Brief excerpt (pages 217-8; forgive my typos, if any):
...Jeffrey Friedl, in his book Mastering Regular Expressions, tackled creating a regular expression to handle the parsing of RFC 822 email addresses. The book is the best reference for understanding regular expressions in Perl or any other context. Many people cite the regular expression he constructs as the only definitive test of whether an Internet email address is valid. But unfortunately these people have misunderstood what it does; it test for compliance with RFC 822. According to RFC 822, these are all syntactically valid email addresses:
          Alfred Neuman <Neuman@BBN-TENEXA>
          ":sysmail"@ Some-Group. Some-Org
          Muhammed.(I am the greatest) Ali @(the)Vegas.WBA
Do any of them look like the type of email address you'd want to capture in an HTML form? It is true that RFC 822 has not been superseded by another RFC and is still a standard, but it is equally true that the problem we are trying to solve is radically different in time and context from the problem that it solved in 1982.

We want an expression to recognize a syntactically valid emai laddress as required on the Internet today. ...

(The examples from this book contain (in chapter 9) a regex to check addresses for validity on what the authors call "today's Internet." It's not as concerned with RFC 822 compliance as it is with real-world usability. I leave it to you to decide if they were successful.)

The authors make a very good point: an email address can be syntactically valid yet for all practical purposes useless. Furthermore, syntactic validity is no guarantee of accuracy (when I don't want to give my own address I use 'bill.gates@microsoft.com').

What I've seen others suggest, and what I do myself, is a two-step process: (1) require people to type the address twice, and check those two inputs for consistency, and (2) send an email to that address with a CGI link back to a validation page. If it fails - they should have been more careful. No amount of RFC-checking will guarantee against typos or misinformation.

This may not fit your purposes at all - perhaps you're just trying this for fun. It's food for thought, though. In my case all I care about is whether the address "works" (whether it reaches the intended recipient), so this solution is perfect.
--
man with no legs, inc.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://107666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-24 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found