Category Archives: Javascript

What is a Valid Email Address?

I’m working on a side project and needed to validate if an email address format was valid.   I started doing searches and found a very interesting article by Ross Kendall.   His javascript implementation strictly implements RFC822, which although out of date [RFC2821 & RFC2822] is better than most alternatives that I came across.

My biggest issue with his script was that it didn’t require the domain to be at least two parts.  This meets spec and is certainly not a bug, however for all practical purposes online it would allow unsuitable email addresses.  I know just enough about regular expressions to realize it was a simple fix to make multiple domain parts required.  So I made the following modifications

I added an optional requiredFQDN parameter that’s intended to be a boolean value.

function isRFC822ValidEmail(sEmail, requireFQDN) {
   if(typeof(requireFQDN) == “undefined”)
      requireFQDN = false;

And then I changed the 0 to many identifier, * to the 1 to many identifier +.

if(requireFQDN)
    sDomain = sDomain.substr(0,sDomain.length-1) + ‘+';

You can download the entire file here.