0

I need to validate this email using JS, I need to check for the @sign and a period. This is what I have now, but if I run all my code it doesn't not validate the @ 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.";
   }
crash
  • 13
  • 1
  • 5

1 Answers1

0

Consider this 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
Nick Zuber
  • 5,467
  • 3
  • 24
  • 48