javascript - Jquery replace only specific characters -
i need replace special characters except #-. below code allows special characters after typing of above mentioned.
$("[id='searchjobautotop']").keyup(function(e){ var start = this.selectionstart, end = this.selectionend; var data= $(this).val() ; var datafull = data.replace(/[^0-9a-za-z#.- ]/g, ''); if(e.which!=37 && e.which!=39 && data.length<2) $(this).val(datafull); this.setselectionrange(start, end); });
please make jsfiddle sample me.
$("[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 me!
Comments
Post a Comment