Email Validation (cross platform)

public function isValidEmail( email : String ) : Bool
{
    var emailExpression : EReg = ~/^[\w-\.]{2,}@[ÅÄÖåäö\w-\.]{2,}\.[a-z]{2,6}$/i;
    return emailExpression.match( email );
}

This method can be used in your neko / PHP / JavaScript and possibly your C++ output, too. It simply compares a passed email address to see if it's valid. It's a little lenient, supporting pretty much any character to the left of the '@' symbol, but then it's surprising what the email standards can support.

Note: It isn't really feasible to express the correct syntax of email addresses with a regular expression. By using the above, you may alienate people that has perfectly good e-mail addresses, but which the above fails to match. Consider sending an activation e-mail instead or use a much more "forgiving" expression:

public function isValidEmail( email : String ) : Bool
{
    var emailExpression : EReg = ~/^[^@]+@.{2,}\.[a-z]{2,6}$/i;
    return emailExpression.match( email );
}

Here is some examples of perfectly valid e-mail addresses:
''"Bo Ström"@example.se
kasper.quist@fågel.example.se
news@爱驾网.中国''
 

Those "special" (Non-English) characters are not allowed per see, but made possible with the help of «punycode», thus the URL http://爱驾网.中国/ gets translated into this http://xn--u0xy3zkiv.xn--fiqs8s/ and vice versa

version #10108, modified 2011-02-06 00:03:24 by Frank