title: Validating email through php and jQuery
body: <p>I want to validate email field which I take on input by using php and jquery.
  But I am unable to figure out my mistake in my program.</p>
  
  <p>Below is the code in <code>index.html</code></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
           &lt;title&gt;
           &lt;/title&gt;
           &lt;meta charset="utf-8" /&gt;
           &lt;link rel="stylesheet" type="text/css" href="css/custom.css" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt;Email: &lt;input type="text" id="myInput" /&gt;&lt;/p&gt;
          &lt;p id="feedbackDiv"&gt;&lt;/p&gt;
          &lt;p&gt;&lt;input type="button" id="myButton" value="Check" /&gt;&lt;/p&gt;
  
      &lt;script type="text/javascript" src="js/jquery-3.1.1.min.js" &gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="js/custom.js" &gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Below is the code in <code>custom.js</code></p>
  
  <pre><code>$(document).ready(function(){
      $('#myButton').on('click',function(){
          var x = $('#myInput').val();
  
          function validateEmail(mail){
              $.post('php/email.php',{email_value_server: mail},function(returnData){
                  $('#feedbackDiv').html(returnData);
              });
          }
  
          $('#myInput').focusin(function(){
              if(x === ''){
                  $('#feedbackDiv').html('Please fill the email address.');
              }else{
                  validateEmail(x);
              }
          }).blur(function(){
              $('#feedbackDiv').html('');
          }).keyup(function(){
              validateEmail(x);
          });
      });
  });
  </code></pre>
  
  <p>Below is the code in <code>email.php</code></p>
  
  <pre><code>&lt;?php
      $y = $_POST['email_value_server'];
      if(isset($y)){
           if(!empty($y)){
               if(filter_var($y,FILTER_VALIDATE_EMAIL) === false){
                   echo "This doesn't appear to be valid email address.";
               }else{
                   echo "Valid email address.";
               }
           }
      }
  ?&gt;
  </code></pre>
  
  <p>I am a beginner in jQuery and php.
  Please comment below for any query.</p>