简体   繁体   中英

jQuery filter asterisk (*) input

I have here a jQuery code that filter special characters:

$("#txtFName").keyup(function () {
      name = $("#txtFName").val();
      name = name.replace(/[^a-zA-Z 0-9.]+/g, '');
      $("#txtFName").val(name);
});

But I only wanted to filter the asterisk (*) character and the remaining are allowed. What adjustment should I do in /[^a-zA-Z 0-9.]+/g to make this? Or there are other work around to do this? Thank you very much!

So you only need to replace * :

$("#txtFName").keyup(function () {
  $(this).val($(this).val().replace(/\*/g, ''));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM