2016-07-22 92 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'); 
    } 
相关问题