Javascript中的电子邮件地址验证

时间:2011-05-20 11:35:49

标签: javascript validation email dictionary

更新问题

大家好,

我想改进我的电子邮件地址验证码。目前,我们有6个不同的电子邮件地址

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

如您所见,有4个变量,当用户的电子邮件地址包含emailPatt2,emailPatt3,emailPatt4时,它将发送到“profil2”页面。对于emailPatt,除了“htc.teleperformance.com”将转到个人资料页面

// 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";}
                },

在主登录过程代码中:

**// 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')
        }]);
    }

    },

那就是退出而不是优化。我想知道是否有字典列表我可以用来查看这里的所有电子邮件地址。它对系统来说有点干净和快速。

谢谢

1 个答案:

答案 0 :(得分:3)

使用正则表达式http://www.regular-expressions.info/email.html

验证电子邮件地址的页面