title: How to validate email address allow only two domains in java script
body: <p>I have a problem in email validation i have two email formats based on those email formats only i need to check the validations  If by mistakenly user enter out of these two emails raise alert message below my code is not working properly how can i do this </p>
  
  <pre><code> var atpos = email.indexOf("@ho.XXX");   
       var atpos1 = email.indexOf("@YYYY");    
          var dotpos = email.lastIndexOf(".com");     
   if (atpos&lt;1 &amp;&amp; atpos1&lt;1 || dotpos&lt;atpos+2 ||dotpos&lt;atpos1+2 || dotpos+2&gt;=email.length){
          alert("Email Should be in @@ho.XXX.com or @YYYY.com");
          document.getElementById("txtEmail").focus();
          return false;
      } 
  </code></pre>
  
  <p>when i am taking the above <code>if-condition</code> it accepts both the email id's. I need to accept only one for at a time. If the user enter both at a time display error message like enter only one email id and when i enter some text after <code>.com</code> like <code>.comyu</code> it accepts without showing any error how to validate <code>.com</code> show error in this case </p>