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.
- Name can be 1 to 64 characters.
- 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
######
}


Douglas Karr

However, it’s written succinctly and definitely a solution that should be acceptable to any enterprise email application.
Thanks, Again!
Doug
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.)
– 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.