javascript - How to Filter the value pasted in TextArea -


have text area enter semicolon separated values, able process keyboard events , validating successfully.how validate same on copy paste.

$(function () {     var kpi = document.getelementbyid('<%=this.d.clientid%>').value;     var tb = $('#<%= textbox.clientid %>');     $(tb).keypress(function (e) {         var regex = new regexp("[0-9;]+$");         var str = string.fromcharcode(!e.charcode ? e.which : e.charcode);         if (regex.test(str) && !($(this).val().match(/;{2,}/))) {             var = $(this).val().match(/;/ig) || [];             var len = as.length;             if (len < kpi) {                 return true;             }         }         e.preventdefault();         return false;     });     $(tb).keyup(function (e) {         var str = string.fromcharcode(!e.charcode ? e.which : e.charcode);         if (($(this).val().match(/[;]{2,}/g))) {             var shortenedstring = $(this).val().substr(0, ($(this).val().length - 1));             $(this).val(shortenedstring);             return true;         }         e.preventdefault();         return false;     });     $(tb).on('paste input propertychange', function (e) {         //validate interger ; on paste , rest not allowed     }) }); 

you try using keyup event post-validate input. pasted value in textarea not available before this, such @ keypress. can determine if it's paste checking, example:

event.ctrlkey 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -