I\'m looking for a way to sanitize input that I paste into the browser, is this possible to do with jQuery?
I\'ve managed to come up with this so far:
This code is working for me either paste from right click or direct copy paste
$('.textbox').on('paste input propertychange', function (e) {
$(this).val( $(this).val().replace(/[^0-9.]/g, '') );
})
When i paste Section 1: Labour Cost
it becomes 1
in text box.
To allow only float value i use this code
//only decimal
$('.textbox').keypress(function(e) {
if(e.which == 46 && $(this).val().indexOf('.') != -1) {
e.preventDefault();
}
if (e.which == 8 || e.which == 46) {
return true;
} else if ( e.which < 48 || e.which > 57) {
e.preventDefault();
}
});