This topic is locked

More complete e-mail validation

9/10/2004 6:24:19 PM
ASPRunnerPro General questions
J
joost author

Hi,
We have added more complete e-mail validation in the validate.html. Maybe something you can use for future version or for other people who have the same need. Please note. We have tested this quickly, but there could still be errors in here. For us we needed to check that there were max 9 e-mail addresses. But that may not be needed for others.
> //    else if(validateObject.type == "IsEmail")

  // Checking existense of "@" and ".".

  // Length of must >= 5 and the "." must

  // not directly precede or follow the "@" - 08/09/04 - Extend email validation

//    if (isWhitespace(validateObject.val)!=true)

//    {

//    if ((validateObject.val.indexOf("@") == -1) || (validateObject.val.charAt(0) == ".") || (validateObject.val.charAt(0) == "@") || (validateObject.len < 6) || (validateObject.val.indexOf(".") == -1) || (validateObject.val.charAt(validateObject.val.indexOf("@")+1) == ".") || (validateObject.val.charAt(validateObject.val.indexOf("@")-1) == "."))

//    {

//    errors += validateObject.HTMLname + "\n";

//    EmailMsg += validateObject.HTMLname + "\n";

//    }

//    }

        if(isWhitespace(validateObject.val)!=true)

        {

            var emails=validateObject.val.split(";");

            if(emails.length>9)

            {

                errors+=validateObject.HTMLname+"\n";

                EmailMsg+=validateObject.HTMLname+": Max 9 email addresses allowed!\n";

            }

            else

            {

                var iCnt=0

                var str=""

                var errstr="";

                var filter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+))|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

                while(iCnt<emails.length)

                {

                    str=emails[iCnt].replace(/^\s
|\s*$/g,"");

                    if(filter.test(str)!=true)

                    {

                        errors+=validateObject.HTMLname+"\n";

                        if(errstr=="")

                            errstr="Failed to validate these email addresses in field "+validateObject.HTMLname+":\n";

                        errstr+="\t"+str+"\n";

                    }

                    iCnt++

                }

                if(!errstr=="")

                {

                    errstr+="The format of an email address should be '<name>@<provider>.<domain>' and multiple addresses need to be separated by a semicolon (;)\n\n";

                    EmailMsg+=errstr;

                }