jQuery - Filter Copy Paste

In this example if the user copy-paste a value in an input field where the class contains 'price', the input is filtered except for decimals, dot, command and minus sign.

function filterCopyPaste() {
    $('input').bind("paste input", function() {
        let className = $(this).attr('class');
        let val = $(this).val();
        if (className.includes('price')) {
            val = val.replace(/[^\d.,-]/g, '');

Sometimes you need to call filterCopyPaste after adding dynamic content or add the onpaste attribute: