Skip to main content
The 2024 Developer Survey results are live! See the results
added 30 characters in body
Source Link
bareMetal
  • 552
  • 1
  • 7
  • 27

Simplest solution is parseInt() .

<input type="number" onkeyup="this.value = parseInt(this.value); this.paste(this.onkeyup);"/>

ParseInt() returns blank(NaN) for E, e, +, - and anything which is not a number.

Use onkeyup and keydown according to your convenience with paste event. For me onkeyup works best,. This works with copy-paste as well

Simplest solution is parseInt() .

<input type="number" onkeyup="this.value = parseInt(this.value); this.paste(this.onkeyup);"/>

ParseInt() returns blank(NaN) for E, e, +, - and anything which is not a number.

Use onkeyup and keydown according to your convenience. For me onkeyup works best, with copy-paste as well

Simplest solution is parseInt() .

<input type="number" onkeyup="this.value = parseInt(this.value); this.paste(this.onkeyup);"/>

ParseInt() returns blank(NaN) for E, e, +, - and anything which is not a number.

Use onkeyup and keydown according to your convenience with paste event. For me onkeyup works best. This works with copy-paste as well

Handled paste
Source Link
bareMetal
  • 552
  • 1
  • 7
  • 27

Simplest solution is parseInt() .

<input type="number" onkeyup="this.value = parseInt(this.value)"; this.paste(this.onkeyup);"/>

ParseInt() returns blank(NaN) for E, e, +, - and anything which is not a number.

Use onkeyup and keydown according to your convenience. For me onkeyup works best, with copy-paste as well

Simplest solution is parseInt() .

<input type="number" onkeyup="this.value = parseInt(this.value)"/>

ParseInt() returns blank(NaN) for E, e, +, - and anything which is not a number.

Simplest solution is parseInt() .

<input type="number" onkeyup="this.value = parseInt(this.value); this.paste(this.onkeyup);"/>

ParseInt() returns blank(NaN) for E, e, +, - and anything which is not a number.

Use onkeyup and keydown according to your convenience. For me onkeyup works best, with copy-paste as well

Source Link
bareMetal
  • 552
  • 1
  • 7
  • 27

Simplest solution is parseInt() .

<input type="number" onkeyup="this.value = parseInt(this.value)"/>

ParseInt() returns blank(NaN) for E, e, +, - and anything which is not a number.