I have the following problem:
Some people in my work copy texts from a few words and paste on the forms that I do (inside the GED), but sometimes in this copy and paste it take with the text some invalid characters, for example this quote: "
I had the idea of capturing the necklace, treating it and then pasting the treated text. Here is the code:
$(document).ready(function(){
var clipboardData, pastedData;
$(":input").on("paste", function (e) {
e.preventDefault();
clipboardData = e.clipboardData || window.clipboardData;
pastedData = clipboardData.getData('text');
// smart single quotes and apostrophe
pastedData = pastedData.replace(/[\u2018\u2019\u201A]/g, "\'");
// smart double quotes
pastedData = pastedData.replace(/[\u201C\u201D\u201E]/g, "\"");
// ellipsis
pastedData = pastedData.replace(/\u2026/g, "...");
// dashes
pastedData = pastedData.replace(/[\u2013\u2014]/g, "-");
this.value += pastedData;
});
});
I used paste when I tried the "value +=" but in that case, whenever someone places the pointer in the middle of an already typed text, it will ignore where the pointer is and paste the content of the paste treated at the end of the text. How can I put the content of the treated paste where the pointer is?