Why is the default max length for an input 524288?
According to the w3c the maximum value is unlimited:
maxlength = number [CN]
When the type attribute has the value "text" or "password", this attribute specifies the maximum number of characters the user may enter. This number may exceed the specified size, in which case the user agent should offer a scrolling mechanism. The default value for this attribute is an unlimited number.
Despite that, I have noticed that in Chrome indeed defaults the maxlength
to 524288, which seems a 'bug 'to me, or at least a deliberate choice to cap the input to 512KB (thanks to Benjamin Udink ten Cate for pointing that out).
Default value of maxLength input in different browsers
I don't know for sure, but I believe that if no maxlength is set on the input, the default is actually unlimited. This is then applied by the browser and is specific to the platform. The W3schools link mentions 512KB as the maximum but that was presumably a value applied by specific browsers.
References:
What is the default maximum length of html input \ text area?
Edit: just checked https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text and correctly there is no default maxlength, so Chrome and Edge are reporting that correctly.
Allow more than 524288 characters in a WebKit text input
It appears this restriction doesn't apply to the textarea
element, which can be substituted in and will work correctly.
$(document).ready(function(){ // Build a really long string var reallyLongString = "abcdefghijklmnopqrstuvwxyz"; for(var i = 0; i < 15; i++){ reallyLongString = reallyLongString + reallyLongString; }
// The important bit $("#inputElement").val(reallyLongString); $("#quantityDisplay").html( "Actual length: " + reallyLongString.length + "<br />" + "Input length: " + $("#inputElement").val().length );})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><textarea id="inputElement" type="text"></textarea><div id="quantityDisplay"></div>
How to disable default maxlength of input field?
According to my test, Chrome has no default value for maxlength
, and I can enter 10,000 characters in an input
field (on Chrome 20 beta, Win 7). You may have tested with actual form submission using GET method, in which case there may be browser-dependent and server-dependent restrictions on the total length of form data.
Inspecting the DOM on Chrome, an input
element has no default maxlength
, but it has maxLength
, with the value 524288.
Text box character limit
This limit is not imposed by MaterializeCSS, it looks like a limitation used by some browsers.
I tested the following snippet on Chrome Developer Tools (48.0.2564.116) and the output is 524288:
document.getElementById("first_name").maxLength = 9999999;
document.getElementById("first_name").maxLength;
There is a question related here (Why is the default max length for an input 524288?).
Input maxlength attribute ignored when inserting value with val(someValue)
It seems that there is no standard limit, but the one that every browser implements (and you can't raise it via javascript). See the following answer:
https://stackoverflow.com/a/26016746/3697452
Javascript maxLength on tag
textarea has a maxlength attribute
<textarea maxlength="number">
spec doesn't put any limit on the limit of this value
but there is a max limit to the integer itself
So, you can put Number.MAX_SAFE_INTEGER
characters in the textarea, which is around
Math.pow(2, 53) - 1 // 9007199254740991
Related Topics
Display Simple HTML in a Native Blackberry Application
How to Semantically Tag Poem Text
How to Put Text Over an Image Without Absolute Positioning or Setting The Image as Backbround
Balanced Text Wrapping in HTML
How to Apply a CSS Style to an Element Name
How to Change an HTML Output of Wcf Service with My Own Content
Firebug-Like Debugger for Google Chrome
How Is Column Width Determined in Browser
Styling Autocomplete Dropdowns in Browsers
Overlap Border of Parent with H2 Margin Negative
Remove HTML Scrollbars But Allow Mousewheel Scrolling
Make an HTML Element Non-Focusable