Jquery replace only specific characters [closed]

$("[id='searchjobautotop']").keyup(function(e) {
             var start = this.selectionStart,
                 end = this.selectionEnd;
             var data = $(this).val();
             var dataFull = data.replace(/([~!@$%^&*()+=`{}\[\]\|\\:;'<>,\/? ])+/g, '');
             if (e.which != 37 && e.which != 39)
                 $(this).val(dataFull);
             this.setSelectionRange(start, end);
             });

This worked for me!

Leave a Comment