Search code examples
javascripthtmlfirefoxmozilla

Input type number decimal not accepting in Firefox


input[type='number'] {
  -moz-appearance: textfield !important;
}

.no-spin::-webkit-inner-spin-button,
.no-spin::-webkit-outer-spin-button {
  -webkit-appearance: none !important;
  margin: 0 !important;
}

.input::-webkit-inner-spin-button,
.input::-webkit-outer-spin-button {
  -webkit-appearance: none !important;
  margin: 0 !important;
}
<input type="number" oninput="this.value = this.value.replace(/[^0-9.]/g,'')" lang="en">

I am unable to get Firefox 60.0.2 to accept period (.) to enter decimal number. But the same is working in chrome. This does not work even with style removed.

How to write proper html input tag with either text or number type but preferably number type so decimal input is accepted


Solution

  • Why not just use type=text, as you already have script to allow only decimals?

    <input type="text" oninput="this.value = this.value.replace(/[^0-9\.]/g, '').split(/\./).slice(0, 2).join('.')" lang="en">