How to allow for dot and comma to be entered in this input field?

Viewed 23

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!

1 Answers

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.

Related