Search code examples
htmlformsinputcross-browserinternet-explorer-11

Input attribute type="number" doesn't work in IE11. How can I get around this?


I have a simple form and one of the input fields is of type number.

<input type="number" step="0.5" required/>

This works in most browsers. However on Internet Explorer 11 the validation for type="number" is flawed. It only allows numeric values, however after a number has been entered the validation seems to stop working.

For example, in most browsers the validation for type="number" works like this:

  • 50 is a valid value
  • example!50 is an invalid value
  • 50example! is an invalid value

Whereas in Internet Explorer it works like this:

  • 50 is a valid value
  • example!50 is an invalid value
  • 50example! is a valid value

How would I ensure that only numeric values are allowed in the input field for Internet Explorer (whilst also allowing step="0.5" to continue working - i.e 10.5 would still be valid even though "." is non-numerical)


Solution

  • Was able to fix the issue with this regex:

    ~r/^\d+(?:\.[05])?$/