in reply to input - E-mail address - how to check string ?
There's a number of email address validation modules on CPAN, e.g. Mail::RFC822::Address, RFC::RFC822::Address, Email::Valid and Mail::Address (which will attempt to extract an email address). None of these cover all the weird little corner cases.
The best tool I've found for this job is isemail, which comes with a very comprehensive test suite designed to test all those corner cases. Unfortunately it's for PHP, not Perl.
Then again you need to ask yourself what you want to do in the first place. Do you want to make sure that an email address is syntactically valid, i.e. conforming to the stipulations of all the relevant RFCs? Or do you want to make sure that an email address works, i.e. that mail sent to it will actually be received?
In practice it's almost always the latter, and your best bet then is to not bother with the RFCs at all and instead simply try to send an email to that address. An email address may be syntactically invalid, yet still work "in the wild". What's more, an email address that IS syntactically valid may not actually work; mail sent to that address may never get read by the intended recipient, or any person at all.
Here's two articles arguing this point.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: input - E-mail address - how to check string ?
by Discipulus (Canon) on Feb 25, 2015 at 12:51 UTC | |
by afoken (Chancellor) on Feb 26, 2015 at 18:40 UTC |