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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -