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.
views:
527answers:
3Examples valid according to RFC2822
- [email protected]
- [email protected]
- [email protected]
- name\@[email protected] – this is a valid email address containing two @ symbols.
- spaces\ are\ [email protected]
- "spaces may be quoted"@example.com
- !#$%&'+-/=.?^`{|}~@[1.0.0.127]
- !#$%&'+-/=.?^`{|}~@[IPv6:0123:4567:89AB:CDEF:0123:4567:89AB:CDEF]
- me(this is a comment)@example.com – comments are discouraged but not prohibited by RFC2822.
Examples invalid according to RFC2822s
- me@
- @example.com
- [email protected]
- [email protected]
- [email protected]
- me.example@com
- me\@example.com
From : http://en.wikibooks.org/wiki/JavaScript/Best_Practices
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:
- [email protected]
- idna_in_clear(?)_text@例子.测试.مثال.آزمایشی
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;
}
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.