如何在JS中验证电子邮件?

时间:2015-12-03 21:16:30

标签: javascript validation email

我需要使用JS验证此电子邮件,我需要检查@sign和一段时间。这就是我现在所拥有的,但如果我运行所有代码,它就不会验证@符号。

if(email.value == "" || !isNaN(email.value) ) {
var re = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
        //something is wrong.
       isValid = false;
       txtFeedback.innerHTML += "<p>Please enter a valid email address.</p>";
        email.nextElementSibling.innerHTML = "Please enter a email address.";
   }

1 个答案:

答案 0 :(得分:0)

考虑这个regex

var regex = /^([\w-+]+(?:\.[\w-+]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,14}(?:\.[a-z]{2})?)$/i;
regex.test(email); // true if valid email