Email Addresses

Ever go to a web site to enter your email address and find that it wouldn’t fit in the field they provided?

It’s amazing in a world of standards that companies (and individuals) continually ignore them and decide for themselves what’s acceptable.

HELLO!

User names (or local part of the address) can be 64 characters long, and domain names can be 255 characters long.

Here is an example of a reasonable well written validation for email addresses — if you want to see poorly done ones in action it doesn’t take too much effort to find ones that limit the entire email address to less than 30 characters!

<?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
######
}

RFC822 superseded by RFC2822.

User names (for email) may contain:

  • A to Z letters, upper and lower case.
  • 0 through 9 digits
  • . (fullstop, period) but not as the first or last character
  • ! # $ % & ‘ * + – / = ? ^ _ ` { | } ~ – all are permitted.

The maximum length of the user is 64 characters; the domain is 255 characters; so with the @ a valid address could be up to 320 characters.

Further, did you know that user names are case sensitive (but domain names are not).  Of course many email systems treat user names as case insensitive.

For information on domain name limitation you should see IANA.

Now you know more than most developers who write code that accepts or uses email addresses!

Originally posted 2008-08-25 22:12:27.