Don't ask to ask, just ask | |
PerlMonks |
Re: Email Validation, Round 2by legLess (Hermit) |
on Aug 24, 2001 at 22:56 UTC ( [id://107666]=note: print w/replies, xml ) | Need Help?? |
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: (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.
In Section
Seekers of Perl Wisdom
|
|