Sets or gets the maximum number of characters that can be entered.


Setting the maxLength property of an input element to a positive number restricts user input, by manual entry or pasting, to text that does not exceed the maxLength. However, it does not limit your ability to change the element's value to one that exceeds maxLength programmatically.

To remove the maximum length restriction that has been set on the input element, set maxLength to null or undefined.

Getting the maxLength property returns the element's current maxLength setting.

The number of characters is calculated by Unicode code points.


numberRead & Write

Was this helpful?

Get an element's maximum length

Copy Code
1let maxLen = $w("#myElement").maxLength; // 40
Set an element's maximum length

Copy Code
1$w("#myElement").maxLength = 40;
Remove an element's maximum length restriction

Copy Code
1$w("#myElement").maxLength = 0;