I’m using the following jQuery plug-in to only allow users to enter certain alpha numeric characters. Can someone please tell me how to update it so it will allow the paste event?
input.keypress(function (e) {
var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);
if (ch.indexOf(key) !== -1 && !e.ctrlKey) {
e.preventDefault();
}
});
If you change from the
keypressto thekeyupevent then the user will be able to complete their paste before the code kicks in and validates.Here is a demo of the different events: http://jsfiddle.net/FckGw/