0

I am trying to implement a cross browser consistent float input type in HTML5. Sofar i have this:

<input type="number" step="any" lang="en-150">

The problem is, all major browsers behave different regarding the input format (comma or period - 1.55 or 1,55).

  • Chrome seems to be the only browser, which works always, also without of a 'lang' attribute.
  • Firefox did not support period (like "1.5") at all, until i added lang="en-150". Now Firefox behaves also like Chrome.
  • But i have still problems with IE (v11). It works with periods, but not with comma. HTML5 validations do not work (i.e. step="0.1", you can still enter sth. like "1,111") + when the form is submitted, it submits just the main number ("1,99" submits "1").

How can i also handle commas on IE?

Gary Thomas
  • 2,291
  • 1
  • 9
  • 21
akcasoy
  • 6,497
  • 13
  • 56
  • 100
  • 1
    One of the ideas of validating `input type=number` is, that users can enter the number using their own locales, it's not purposed to accept any decimal delimiter. However, this seems to have been implemented poorly in IE, you've to replace a possible comma with the dot before submitting. Notice, that the value of the element is a string despite of the type of the input. – Teemu Feb 25 '20 at 08:36
  • thanks. as you also suggest, i now replace the comma with dot before submitting. – akcasoy Feb 25 '20 at 10:59
  • The comma doesn't work for me. I think that's due to the OS language/region settings. For me, the validation also works in IE with a `step` attribute. You could refer to [this answer](https://stackoverflow.com/questions/15303940/how-to-handle-floats-and-decimal-separators-with-html5-input-type-number/16680098#16680098). The result of the jsfiddle demo in IE is like this: https://i.stack.imgur.com/S1oZL.gif. If IE doesn't recognize comma as decimal point, I think you can only manually replace it. It seems that you have had a solution, you can also put it as an answer to help others. – Yu Zhou Feb 26 '20 at 04:48

0 Answers0