I have seen a few of these question on here and I can not seem to get this to work.
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.
(whitespace meaning anything that can not be done using the enter key or spacebar... Things like the tab key etc.)
I need this to happen because this section will be going into a json, and without doing this, it will break the json string.
I will be doing other checks regarding quotes etc.
Here is the code I have used:
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);
});
});
Thanks in advance for any help provided.
Try Following