In comp.lang.javascript message <
[email protected]>
, Wed, 20 Feb 2008 18:41:55, Evertjan. <
[email protected]>
posted:
A simpler and more correct form would be:
var pattern = /^[a-z\d_.-]+@[a-z\d_.-]+\.[a-z]{2,}$/i;
But that does not make it perfect, as better tests can be made.
Unless one is an ISP or mailer writer concerned with the issuing of new
E-mail addresses, it is not necessarily wise to check for rigorous RFC
compliance. It is easy to think of at least one major software house,
and of at least one major Web site, that has shown definite disregard
(whether by ignorance or malice) for pre-existing standards such as
those in RFCs and of ISO/IEC; they might well have issued addresses
outside what RFCs allowed.
An issuer should comply with the standards, but may not need to allow
all that the RFCs permit.
Conversely, one who checks E-mail addresses entered as data should allow
at least all that the RFCs etc. permit; but may, and might need to,
allow more, if all working addresses are to be accepted. That is, of
course, apart from any specific requirements such as disallowing .dk
because of a specific anti-bacon policy.
Since the only way of telling whether a supplied E-address is actually
good is to use it to send a message and then to get reliable evidence of
true receipt, there's little point in doing more than checking that the
string could be an E-address and is not, for example, blank, a telephone
number, a name, a postal address.
For mailing, testing with /.@./ is probably adequate in practice; but
/\S+@\S+\.\S$/ seems better.