0

The line below restrict the input to be numbers only. How can this be adjusted to accept dot and comma?

Numbers only: <input oninput="this.value=this.value.replace(/(?![0-9])./gmi,'')"></input>

Appreciate your help!

ATP
  • 2,939
  • 4
  • 13
  • 34
onit
  • 2,275
  • 11
  • 25

1 Answers1

2

You may replace on the pattern [^0-9.,]+:

<input oninput="this.value=this.value.replace(/[^0-9.,]+/gmi,'')"></input>

Note that technically we should also disallow more than one decimal point, and we also should not allow thousands comma separators in the wrong place.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360