

Ask HN: What length do you choose for email fields? - kondro

I know that the maximum length of email addresses can be 256 characters (http://en.wikipedia.org/wiki/Email_address) however, I always feel dirty about defining varchars with such large bounds and reserving such a large index size for email addresses.<p>Whilst obviously not in spec, I often set my email fields to 100 characters as I think that even an email address of that size is impracticable for day-to-day usage and should cover off 99.999% of address cases.<p>So I ask you, how big do you usually make your email address fields?
======
rfugger
254 characters.

From <http://www.dominicsayers.com/isemail/>:

"Myth: The maximum length of an email address is 320 characters

This arises from the simple arithmetic of maximum length of a domain (255
characters) + maximum length of a mailbox (64 characters) + the @ symbol = 320
characters. Wrong.

This canard is actually documented in the original version of RFC3696. It was
corrected in the errata, but nobody reads the errata (except me it would
appear).

There's actually a restriction from RFC 5321 on the path element of an SMTP
transaction of 256 characters. But this includes angled brackets around the
email address, so the maximum length of an email address is 254 characters.
You read it here first.

This is not a new restriction - it goes right the way back to RFC 821 and was
also in RFC 2821."

------
jacquesm
I just did a little checking for you over a log of what people try to enter in
to an email field in a form:

<5: 1056713 (none or fake)

5-9: 6052

10-19: 226676

20-29: 274956

30-39: 8912

40-49: 196 (from here on they all seem to be either fake or badly formed)

50-59: 29

60-69: 11

70-79: 2

> 80: 0

That's probably not very representative, but it gives you an idea of what
people tend to enter in to email fields if you are not too strict about what
you accept in the form itself.

So, valid addresses across this sample appear to be between 5 and 39
characters, with the shortest valid address in the log at 8 characters. It's
technically possible to have both shorter and longer ones but the chances of
those being actual addresses are probably quite low.

All that said, I'd stick with the RFC anyway.

~~~
wladimir
I'm seriously curious why someone would choose a mail address >=30 characters.

~~~
cnvogel
The company I work for has a policy to take your full name in the local part.
So if you are

Juan Alfonso de Borja y Estevez

then by default you'll have a email-address of

juan_alfonso_de_borjy_y_estevez@company.com

This is just the first hit for "long spanish name" I found on google, but I
have colleagues that have email-addresses that are that long or (in a few
cases) even longer.

------
DanHulton
I seem to remember a spec somewhere detailing that email addresses could be up
to 320 characters, and that's what I use. Ensures that I'll never have an
issue, yes, but also WAY overkill for most cases, so take with a grain of
salt.

------
zbanks
I tend to err towards 256.

My rationale is this: what percent of the DB will the extra 156 characters
take? If I have 1K or less users, an extra 150KB of storage is negligible. If
I have 1M users, 150MB is also silly.

~~~
kondro
I guess, but I don't want to run into the 1KB index size per row limit in
MySQL (unless that has changed without me knowing) either and I have other
fields I want to index as well.

------
wccrawford
I think most of what I've seen has been 255 characters.

But really, it should follow the RFC and use 320.

[http://askville.amazon.com/maximum-length-allowed-email-
addr...](http://askville.amazon.com/maximum-length-allowed-email-
address/AnswerViewer.do?requestId=1166932)

------
jasonemerick
Default max length of an email field in Django is 75 characters.

[http://docs.djangoproject.com/en/1.2/ref/models/fields/#emai...](http://docs.djangoproject.com/en/1.2/ref/models/fields/#emailfield)

------
mikey_p
I've seen as low as 64 and as high as 254. I tend to err on the side of spec
vs. performance when it comes to this sort of thing.

------
albahk
My email fields are usually varchar(128) - which seems like a nice round
number to me.

------
Slumberthud
I use 100 chars, too. No problems to date.

------
zzo38
To follow exactly the RFC.

