0

If there are any changes tell me... It should accept general mail ids "xyz@adaf@fa.com" should not accept "xyzadaf@fa.com","xyz@ad.co.in" should accept

function checkEmail(){
  var emailFormat = /^[a-zA-Z0-9._-]+[@]{1}[.]{1}[a-z]{2,3}[.]*[a-z]{0,3}$/;
  var email = document.getElementById("email").value;
  var emailStatus = emailFormat.exec(email);
  if(emailStatus == "true"){
 alert("success");
  }
  else(emailStatus == "false"){
 alert("Try again");
   }
}
GAntoine
  • 1,265
  • 2
  • 16
  • 28

1 Answers1

0

I have changed your code as follows and it seems it is working fine. Please check.

function checkEmail(){
debugger;
 var emailFormat = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
 var email = document.getElementById("email").value;
 var emailStatus = emailFormat.exec(email);
 if(emailStatus)
  alert("valid email id");
 else
  alert("Not valid");
}
checkEmail();
<input type="text" id="email" value="xyzad@af@fa.com" />

You can also see the fiddle here.

Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140