Strip white spaces on input

前端 未结 4 658
一个人的身影
一个人的身影 2020-12-02 14:56

I have a field that does not need any white spaces. I need to remove any as they are entered. Here\'s what I\'m trying... no luck so far

$(\'#noSpacesField\'         


        
4条回答
  •  清歌不尽
    2020-12-02 15:47

    $('#noSpacesField').keyup(function() {
      $(this).val($(this).val().replace(/ +?/g, ''));
    });
    

    This will remove spaces as you type, and will also remove the tab char.

提交回复
热议问题