HTML5 Input Type Number 16 Digits or More Chrome Replaces with Zeroes
When the number input is blurred, Chrome parses the number. According to the WHATWG standard, it should convert it to an IEEE 754 double-precision floating-point number, just like the way numbers are represented in JavaScript. And also like in JavaScript, there's a limit to the precision that these numbers can have, hence the rounding.
You might want to use <input type="text">
instead..
HTML5 input box with type=number does not accept comma in Chrome browser
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.
maxlength ignored for input type=number in Chrome
From MDN's documentation for <input>
If the value of the type attribute is
text
,search
,password
,tel
, orurl
, this attribute specifies the maximum number of characters (in Unicode code points) that the user can enter; for other control types, it is ignored.
So maxlength
is ignored on <input type="number">
by design.
Depending on your needs, you can use the min
and max
attributes as inon suggested in his/her answer (NB: this will only define a constrained range, not the actual character length of the value, though -9999 to 9999 will cover all 0-4 digit numbers), or you can use a regular text input and enforce validation on the field with the new pattern
attribute:
<input type="text" pattern="\d*" maxlength="4">
Related Topics
How Might I Force a Floating Div to Match The Height of Another Floating Div
Media Queries Not Working Inside an Iframe
How to Write Content That Screen Readers Will Ignore
How to Get a Flexbox to Have a Center Fixed and a Bottom Fixed Children Together
@Media Queries and Image Swapping
How to Use Custom Fonts in an HTML5 Canvas Element
How to Create a Heart Shape Using CSS
Is It Ok to Have Multiple HTML Forms with The Same Name
Border Around Specific Rows in a Table
Purpose of The Crossorigin Attribute...
Why Is Chrome Showing a "Please Fill Out This Field" Tooltip on Empty Fields
How to Make a Flex Item Not Fill The Height of The Flex Container
Make a List Item Clickable (HTML/CSS)
How to Open Native iOS App (Calendar, Notes...) from a Link on Website
Select Size Attribute Size Not Working in Chrome/Safari
When Multiple Instances of Same Images Are Embedded in an HTML, Does That Load The Image Once