2016-07-22 51 views

回答

0

使用。

function IsValidEmail(emailText) { 
    var atpos = emailText.indexOf("@"); 
    var dotpos = emailText.lastIndexOf("."); 
    if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailText.length) { 
     return false; 
    } 
    return true; 
} 
1

因爲你的邏輯倒 - 你警告,如果事情一個有效的電子郵件地址。

if (valid email address) { alert }[email protected]不是有效的電子郵件地址。沒有警報。

嘗試!反轉測試的結果:

if (! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test('[email protected]')) { 
    alert('Please make sure the email is valid.'); 
} 
0

您可以使用此一個。 [點] 2,3字符作爲 每個域後,將支持

var email_filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 
    if (email_filter.test('[email protected]')) { 
     alert('Email is valid'); 
    } 
相關問題