title: Javascript issue with Replace Character
body: <p>I am trying to replace special characters i.e &lt;,>,&amp; from input field on blur and keypress. And the code is working fine but the problem is, once user enter the desired string and then try to edit that string it will move the cursor to the end of the string, So the user isn't able to edit the string in between. How do I make this script more user friendly so that user can edit the existing string from anywhere.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;input type="text" class="prevent-special" name="name" value="HelloWorld" &gt;
  </code></pre>
  
  <p><strong>Script</strong></p>
  
  <pre><code>$('.prevent-special').on('keypress blur',function(e){
      //console.log(e.keyCode);
      $(this).val($(this).val().replace(/\&lt;|\&gt;|\&amp;+/g,''));
  })  
  </code></pre>
  
  <p><a href="https://jsfiddle.net/toppest_1/a5x2mgnv/1/" rel="nofollow noreferrer"><strong>JS Example</strong></a></p>