title: How to check upload file is txt or modified extension manually?
body: <p>I created one web page where i want to upload only text file using JavaScript and it is working fine. </p>
  
  <p>Using below JavaScript, it is checking upload file is txt or not?</p>
  
  <pre><code>&lt;script&gt;
    function checkExt() {
      if(document.mainForm.myfile.value.lastIndexOf(".txt")==-1) {
        alert("Please upload only .txt extention file");
        return false;
      }
    }
  &lt;/script&gt;
  
  &lt;form name="mainForm"&gt;
     &lt;input type="file" name="myfile" onchange="checkExt();"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><a href="http://jsfiddle.net/Lnwr254v/2/" rel="nofollow noreferrer">Live Demo Here</a></p>
  
  <p><strong>Problem</strong>: If I change extension of file .exe to .txt manually then it is also being upload because i'm checking file's extension only. So My question is how to protect from <strong>exe file</strong> (which is <strong><em>Manually changed to txt</em></strong>) to upload.</p>
  
  <p>I want to stop upload exe, jar files which is changed or renamed forcefully or manually.</p>