title: All whitespace removed and plain text when pasting in all input and text fields
body: <p>I have seen a few of these question on here and I can not seem to get this to work.</p>
  
  <p>Basically I want the copy and paste events to be plain text only and to remove all white space apart from line breaks and text spaces within the copy and paste process.</p>
  
  <p>(whitespace meaning anything that can not be done using the enter key or spacebar... Things like the tab key etc.)</p>
  
  <p>I need this to happen because this section will be going into a json, and without doing this, it will break the json string.</p>
  
  <p>I will be doing other checks regarding quotes etc.</p>
  
  <p><a href="https://jsfiddle.net/robertg/awm2kgzx/10/" rel="nofollow noreferrer">You can see a jfiddle here</a></p>
  
  <p>Here is the code I have used:</p>
  
  <pre><code>jQuery(document).ready(function($){
  
  "use strict";
  
  document.querySelector("input, textarea").addEventListener("paste", function(e) {
      e.preventDefault();
      var text = e.clipboardData.getData("text/plain");
      text = text.replace(/^\s+|\s+$/g,'');
      document.execCommand("insertHTML", false, text);
  });
  </code></pre>
  
  <p>});</p>
  
  <p>Thanks in advance for any help provided.</p>