The IsValidEmail( ) functionThis function resides in the utils/email.asp Server Side Include. As you can see below, the function simply calls GetEmailRating( ), and displays a message if the function fails...function IsValidEmail ( sEmail, nLevel )
{
// test all email addresses sent in
var sEmailList = sEmail.split ( /[\s;,]/ );
var nEmail;
for ( nEmail in sEmailList )
{
if ( hexVeLevelBad == GetEmailRating ( sEmailList [ nEmail ], nLevel ) )
{
Out ( '<center><b><font color="red">"' + sEmailList [ nEmail ] + '" is an invalid email address - try again!</font></b>' );
Out ( '<br><a href="/ValidateEmail.html">(See how this email validation was done)</a></center><p>' );
return false;
}
}
return true;
}
|
...so we really have to look at GetEmailRating( ). var hexVeLevelSyntax = 1;
var hexVeLevelDns = 2;
var hexVeLevelSmtp = 3;
function GetEmailRating ( sEmail, nLevel )
{
// simple syntax validation if no Hexillion component
if ( !bUseHexillion )
{
if ( IsValidEmailSyntax ( sEmail ) )
return hexVeLevelSyntax;
return hexVeLevelBad;
}
//...use HexValidEmail
|
To start with, I declare some global variables that are passed into these validation functions. Think of these as const's or enum's that are used to determine the level of confidence in the email address. Pass in hexVeLevelDns and Hexillion's cool HexValidEmail component will ensure that the domain in the email address exists. These constants are also used as return values from the functions. If we're not going to be taking advantage of HexValidEmail, and hence bUseHexillion is set to false in include/config.asp, we call a function that uses a regular expression to determine if the syntax of the email address is valid. Thanks again to Ed Courtenay for donating the regular expression used to validate the syntax. I'll leave you to explore that and the rest of the source code concerning email validation by viewing the entire utils/email.asp source code at the end of the article. For more information on HexValidEmail, and the 3 levels of validation it offers, see my live demonstration. Part 3: Making up the email... |