HTML5 input box with type="number" does not accept comma in Chrome browser

38,108

Solution 1

As of now (30/08/2017), Antoine Thiry's answer seems to be no longer valid in Chrome (my version is 60.0.3112.113). Unfortunately I don't have any other suggestion, other than simulating type="number" with javascript.

Solution 2

actually, if i read the documentation correctly, pattern is not supported for type=number. hence, stick to type=text and then add pattern="..." for the front end validation. in the next step, you will then need to convert the text input into a real number if it wasn't compatible to JavaScript/computing format.

2017 and still no good solution for this common problem...

Share:
38,108
Jana Weschenfelder
Author by

Jana Weschenfelder

Because of publishing problems of... http://stackoverflow.com/questions/20915375/windows-8-1-touch-pad-of-toshiba-satellite-p50-a-m13-doesnt-work-anymore-solu/20915376 ...the whole thread has moved to: http://forums.computers.toshiba-europe.com/forums/thread.jspa?threadID=74833 Remark: I wasn't in the mood to post the solution for that problem three times, sorry. The thread on the SuperUser site got deleted again: a) because I posted my answer together with the question (but I should wait many hours there first), b) because I didn't want to cause people to think about a problem which was solved already, c) and because it was really insolent to edit and to delete the answer without to inform the originator of the post first. Either the the SuperUser site becomes more user-friendly like StackOverflow, or they have seen me the last time there. The StackOverflow site offered me the option to post the answer together with the question, too. I await the same from the SuperUser site. Please tell me if SuperUser also wants to become a knowledge database sometime, but at the moment it doesn't look like that for me, they don't really have an interest in solutions for problems. The discussion about when to post an answer there seems to be the bigger problem there at the moment. In other words: Something is wrong there. Wrong priorities. ???

Updated on June 12, 2020

Comments

  • Jana Weschenfelder
    Jana Weschenfelder almost 4 years

    I am using a HTML5 input box with type="number". Regarding to some documentations, it should be possible to enter a number with comma (not with period) if I also use the lang="" attribute. It is working in Firefox, but not in Chrome (does not accept a comma). How can I get Chrome to accept the comma in the input box. My problem is that our German users expect that they can enter a comma instead of a period there.

    https://jsfiddle.net/byte2702/y3Lpfw7m/

    Please enter a number with comma: <br/>
    <input id="num" type="number" step="any" lang="de" pattern="-?[0-9]+[\,.]*[0-9]+" />