Dec
6th

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:

loremaipsumadolorasitaametbaconsectetueraadipiscingaelitanullamc@lo
remaipsumadolorasitaametbaconsectetueraadipiscingaelitcaSedaidametu
sautanisiavehiculaaluctuscaPellentesqueatinciduntbadiamaidacondimntum
arutrumbaturpisamassaaconsectetueraarcubaeuatinciduntaliberoaaugueav
estibulumaeratcaPhasellusatinciduntaturpisaduis.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: http://derrick.pallas.us/email-validator/
# License: Academic Free License 2.1
# Version: 2006-12-01a
if (!ereg(”
. ‘^’
. ‘[-!#$%&\'*+/0-9=?A-Z^_a-z{|}~]‘
. ‘(\\.?[-!#$%&\'*+/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 && !gethostbynamel( $domain ) ) return false;
return true;
# END
######
}

RSS feed | Trackback URI

6 Comments »

Comment by no imageDerrick Pallas (SezWho)
2006-12-08 03:43:20

I’m glad someone found that useful! Searching on Google for “email regexp” reveals a lot of regular expressions that don’t sync up with the RFC.
Rate this:
3.0
 
Comment by no imageDouglas Karr (SezWho)
2006-12-08 16:34:05

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

Rate this:
2.9
 
Comment by no imageDerrick Pallas (SezWho)
2006-12-09 19:06:36

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.)

Rate this:
3.0
 
Comment by no imageMark Bye (SezWho)
2008-04-02 17:13:56

Actually RFC2821 IS the correct reference for the email address length. I found it there, but not in RFC 2822.
Rate this:
1.6
 
Comment by no imageKristian (SezWho)
2008-06-07 22:57:44

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.

Rate this:
1.6
 
2008-08-26 01:12:23

[...] function isValidAddress( $email, $check = false ) { ############################## # PHP Email Address Validator # (C) Derrick [...]
 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

My Comment Policy: I moderate comments. Please be patient:

  • Spam will happily be destroyed.
  • Use your real name, not some keywords. Otherwise it will be destroyed.
  • Mean comments aren't necessary. If I don't post them I will reply personally to let you know why.
  • Lewd comments will be edited, I don't want my readers leaving because of offensive content.
Great debate, criticism and colorful commentary is always appreciated and approved!