MaxLength

Returns or sets a value indicating whether there is a maximum number of characters that can be entered in the TextBox control and, if so, specifies the maximum number of characters that can be entered.

Note In DBCS (double-byte character set) systems, each character can take up to two bytes instead of only one, which limits the number of characters you can enter.

Syntax

object.MaxLength [= value]

The parts of the MaxLength property syntax are described in the following table.

Part Description
object An object expression that evaluates to an object.
value An integer specifying the maximum number of characters a user can enter in a TextBox control. The default for the MaxLength property is 0. This indicates no maximum other than that created by memory constraints on the user's system for single-line TextBox controls and a maximum of approximately 32K for multiple-line TextBox controls. Any number greater than 0 indicates the maximum number of characters.

Remarks

Use the MaxLength property to limit the number of characters a user can enter in a TextBox.

If text that exceeds the MaxLength property setting is assigned to a TextBox from code, no error occurs; however, only the maximum number of characters are assigned to the Text property, and extra characters are truncated. Changing this property does not affect the current contents of a TextBox, but will affect any subsequent changes to the contents.