簡體   English   中英

用Javascript驗證電子郵件地址

[英]Email address validation in Javascript

更新問題

大家好,

我想改善我的電子郵件地址驗證碼。 目前,我們有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')
        }]);
    }

    },

那是完全沒有優化的。 我想知道是否有字典列表,我可以用來查看這里的所有電子郵件地址。 對於系統來說,它將有點干凈和快速。

謝謝

有關使用正則表達式驗證電子郵件地址的頁面http://www.regular-expressions.info/email.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM