Valid Email Address Length

I had to do some digging today to find it, but did you know what the valid length of an email address is? It’s actually broken into parts… Name@Domain.com. This is according to RFC2822.

  1. Name can be 1 to 64 characters.
  2. Domain can be 1 to 255 characters.

Wow… that means that this could be a valid email address:


loremaipsumadolorasitaametbaconsectetueraadipiscin
gaelitanullamc@loremaipsumadolorasitaametbaconsect
etueraadipiscingaelitcaSedaidametusautanisiavehicu
laaluctuscaPellentesqueatinciduntbadiamaidacondimn
tumarutrumbaturpisamassaaconsectetueraarcubaeuatin
ciduntaliberoaaugueavestibulumaeratcaPhasellusatin
ciduntaturpisaduis.com

Try fitting that on a business card! Ironically, most email address fields are limited to 100 characters on the web. That’s actually not valid. If you’d like to validate an email address for proper construction utilizing PHP, I found this snippet on the net:

<?php function isValidAddress( $email, $check = false )
{
##############################
# PHP Email Address Validator
# (C) Derrick Pallas
#
# Authors: Derrick Pallas
# Website: <a href="http://derrick.pallas.us/email-validator/">http://derrick.pallas.us/email-validator/</a>
# License: Academic Free License 2.1
# Version: 2006-12-01a
if (!ereg(''
. '^'
. '[-!#$%&amp;'*+/0-9=?A-Z^_a-z{|}~]'
. '(\.?[-!#$%&amp;'*+/0-9=?A-Z^_a-z{|}~])*'
. '@'
. '[a-zA-Z](-?[a-zA-Z0-9])*'
. '(\.[a-zA-Z](-?[a-zA-Z0-9])*)+'
. '$'
, $email
) ) return false;
list( $local, $domain ) = split( "@", $email, 2 );
if ( strlen($local) > 64 || strlen($domain) > 255 ) return false;
if ( $check &amp;&amp; !gethostbynamel( $domain ) ) return false;
return true;
# END
######
}

Leave a Reply

  1. Yes, I noticed the lack of compliance of other solutions with the RFC as well. I have noticed, though, that even this regex is atypical and not the standard. I remember reading the actual regex (allowing < ,>, , etc) is too intensive for most processes.

    However, it’s written succinctly and definitely a solution that should be acceptable to any enterprise email application.

    Thanks, Again!
    Doug

  2. Unfortunately, I linked that page to the wrong RFC (2821 instead of 2822) but that’s been corrected. The angle brackets can not be part of the local or domain parts of an email address; rather, they represent tokenization points, i.e. they can be used to surround an email address (for instance in your mail reader) precisely because they can not be part of the address.

    One thing that my function doesn’t do is worry about the quoted form of email addresses — where the local part appears in double quotes — because RFC2821 essentially says that no one should ever have to write their address that way. (I believe the form is for backwards compatibility and is now bad practice.)

  3. There is a restriction in RFC 2821 on the length of an address in MAIL and RCPT commands of 256 characters. The upper limit on address lengths should normally be considered to be 256.

    — Source: RFC 3696 Errata

    Also, because RFC 2181 says “A full domain name is limited to 255 octets”, it’s repeatedly misinterpreted by people (including the writers of other RFCs) as meaning that domain names can be 255 chars long. But RFC2181 is talking about DNS protocol-level representation on the wire, not printable characters.

    The maximum length of a domain name is 253 chars (254 including trailing dot, 255 octets on the wire with terminating null). And that is what BIND and DiG implement.