views:

527

answers:

3

Does anyone have a list of email addresses that I can use to test my JS address validation script? I'm looking for as complete of a list as is reasonable to test the most common edge cases, if not all cases.

+6  A: 

Examples valid according to RFC2822

Examples invalid according to RFC2822s

From : http://en.wikibooks.org/wiki/JavaScript/Best_Practices

Michael Wolfenden
+1 | [email protected] is one that I try to use all the time (read: Gmail filters) but is classed as invalid for just about every site that has "rolled it's own" without regard to RFC2822. It's infuriating!
Pat
A: 

The domain part (after the last @), is a series of string labels divided by a dot.

Each label is a string of 1 to 63 octets consisting of A-Z, a-z 0-9 or hyphen (-)

The maximum size of the domain is 255 octets.

To be compatible with arpanet, each label must start with a letter and end with a letter or digit but some TLD:s now allows an all numeric domain, like 0.nu

Note that the TLD is allowed to be 63 octets. Very many scrips wrongly restricts it to 2-3 octets making domain.name invalid.

Example?

abcdefghijklmnopqrstuvwxyz.ABCDEFGHIJKLMNOPQRSTUVWXYZ.!#$%&'+-/=.?^`{|}~@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z.0.1.2.3.4.5.6.7.8.9.a-z.A-Z.0-9.a0.b1.c2.d3.e4.f5.g6.h7.i8.j9.K0.L1.M2.N3.O.domain.name

(and no, it isn't registered)

Update: With IDNA almost everything is possible:

See also:

http://stackoverflow.com/questions/3232/how-far-should-one-take-e-mail-address-validation

http://www.leshazlewood.com/?p=5

Update: Bobince suggested to test for a dot in the domain name.

Summary: Only test for @ and a dot in the domain part and then send a confirmation email.

Here is an example that test for @ and dot:

  • There must be at least one @
  • There must be at least one char in the local part ( pos > 0)
  • There must be at least one dot in the domain part
  • The domain part must be at lest 4 characters

Here is a simple one:

function isEmail(address) {
    var pos = address.lastIndexOf("@");
    return pos > 0 && (address.lastIndexOf(".") > pos) && (address.length - pos > 4);
}

Or a function that returns the local and domain part in an object ( if you want to process it even further, for example convert it to punycode)

function isEmail(address) {
    var pos = address.lastIndexOf("@");
    return pos > 0 && (address.lastIndexOf(".") > pos) && (address.length - pos > 4) ? 
    {
     local:address.substr(0,pos < 0 ? 0 : pos),
     domain:address.substr(pos+1)
    }: false;
}
some
Testing for ‘.’ is also useful to catch the people who just put ‘hotmail’ with no TLD. We can, I think, safely assume no-one will be filling in an address @ a TLD itself.
bobince
I'm not sure if it is legal or not to have an address at the TLD. Technically it should be possible, but I am not aware of any that have it.
some
+1  A: 

I've now collated test cases from Cal Henderson, Dave Child, Phil Haack, Doug Lovell and RFC 3696. 158 test addresses in all.

I ran all these tests against all the validators I could find. The comparison is here: http://www.dominicsayers.com/isemail

I'll try to keep this page up-to-date as people enhance their validators. Thanks to Cal, Dave and Phil for their help and co-operation in compiling these tests and constructive criticism of my own validator.

People should be aware of the errata against RFC 3696 in particular. Three of the canonical examples are in fact invalid addresses. And the maximum length of an address is 254 or 256 characters, not 320.

Dominic Sayers