Javascript Regular Expressions - Replace non-numeric characters

前端 未结 10 1042
清歌不尽
清歌不尽 2021-01-30 12:32

This works:

var.replace(/[^0-9]+/g, \'\');  

That simple snippet will replace anything that is not a number with nothing.

But decimals

10条回答
  •  半阙折子戏
    2021-01-30 12:56

    Sweet and short inline replacing of non-numerical characters in the ASP.Net Textbox:

     
    

    Alter the regex part as you'ld like. Lots and lots of people complain about the cursor going straight to the end when using the arrow keys, but people tend to deal with this without noticing it for instance, arrow... arrow... arrow... okay then... backspace back space, enter the new chars.

提交回复
热议问题