简体   繁体   中英

Email address validation in Javascript

Update the question

Hello All,

I would like improve my email address validation code. Currently, we have 6 different email address

var emailPatt=/@(tomtom|stream|teleperformance|htc.teleperformance).com/i;
var emailPattUS2=/@(teleperformance).com/i;
var emailPattUS3=/@(hispanic).corp/i
var emailPattUS4=/@(htc).to/i

As you see, there are 4 variables, when users' email address have emailPatt2, emailPatt3, emailPatt4, it will send to "profil2" page. For emailPatt except "htc.teleperformance.com" will go to profile page

// For // Tomtom.com and stream.com email address will redirect to profile page
//Htc.to, Htc.teleperformance.com, Teleperformance.com, Hispanic.corp will go to prolfe2 page. 


else if(emailPattUS2.test(eo.data.username)|| emailPattUS3.test(eo.data.username)|| emailPattUS4.test(eo.data.username)) //If the email is teleperformance.com
            {document.location.href="/app/account/profile2";}
                else
                    {document.location.href="/app/account/profile";}
                },

In the main login process code:

**// If login's email address is one of these: 
// Tomtom.com
//Stream.com
//Htc.to
//Htc.teleperformance.com
//Teleperformance.com
// Hispanic.corp
// then Login code will fire event (loginFormSubmitRequest) , it will check email address //and password in dataase

if(emailPatt.test(eo.data.username)|| emailPattUS3.test(eo.data.username)||emailPattUS4.test(eo.data.username)) //Search the regualr expres between string
    {
       // alert("test works");
        RightNow.Event.fire("evt_loginFormSubmitRequest", eo);
        new YAHOO.util.Anim("rn_" + this.instanceID + "_Content", { opacity: { to: 0 } }, 0.5, YAHOO.util.Easing.easeOut).animate();
        YAHOO.util.Dom.addClass("rn_" + this.instanceID, 'rn_ContentLoading');

       //since this form is submitted by script, force ie to do auto_complete
        if(YAHOO.env.ua.ie > 0)
        {
        if(window.external && "AutoCompleteSaveForm" in window.external)
        {
            var form = document.getElementById("rn_" + this.instanceID + "_Form");
            if(form)
            window.external.AutoCompleteSaveForm(form);
        }
        }
        return false;
    }

// When the email address is not from the list, they will not fire login event. throw
//error message.
//
//
    else if(!emailPatt.test(eo.data.username)|| !emailPattUS3.test(eo.data.username)||!emailPattUS4.test(eo.data.username))
    {
       //alert(emailPatt.test(eo.data.username));
       // alert ("not tomtom email address");
        me._onLoginResponse("evt_loginFormSubmitResponse", [{
        w_id : eo.w_id,
        result : 0,
        message : RightNow.Interface.getMessage('EMAIL_IS_NOT_VALID_MSG')
        }]);
    }

    },

That is quit not optimize at all. I am wondering whether there is dictionary list i can use to look though all the email address in here. It will a bit clean and fast for the system .

Thanks

有关使用正则表达式验证电子邮件地址的页面http://www.regular-expressions.info/email.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM