The MaskTextBox control represents a text input control that constrains the user input to a specified mask. Use the MaskTextBox for data with fixed length and defined format, such as phone numbers, SSN-s, zip codes, etc.
Use the Mask property to set the input mask for the control. You can use the following symbols to specify the allowed set of characters for any position:
Character | Description |
---|---|
0 | Indicates that the specified position can only hold a digit. |
9 | Indicates that the specified position can hold a digit or it could be empty. |
L | Indicates that the specified position can only hold a letter. |
l | Indicates that the specified position can hold a letter or it could be empty. |
A | Indicates that the specified position can hold either a digit or a letter. |
a | Indicates that the specified position can hold either a digit or a letter or it could be empty. |
? | Indicates that the specified position can hold any character. |
\ | Escape char. Indicates that the next character in the mask should be treated as a literal. |
any other | Any other symbols are displayed as literals. |
Use the MaskTextBox.Text or MaskTextBox.Value properties to get or set the control's text.
Use the PromptChar property to specify the character used for a blank position in control's input. By setting the AllowEmptyInput property you can define whether or not empty string values are considered valid for the control.
Adjust the interaction with the control by setting the SubmitOnEnter and AutoPostBack properties according to your needs.
By setting the EmptyText property you can display a hint to the user, and by setting the Label and LabelPosition properties you can specify a caption for the control.
The following events are exposed by the MaskTextBox class.
Event | Event arguments | Description |
---|---|---|
ValueChangedEventArgs<String> | Raised when the control's value has changed. |
You can access the control on the client side by its ClientID.
JavaScript
![]() |
---|
var maskBox = $find("MaskTextBox1"); |
Use the get_text and set_text or get_value and set_value methods to get or set the control's text.
JavaScript
![]() |
---|
maskBox.set_text('(0123)456789'); |
The following client-side events are exposed by the MaskTextBox class.
Event | Event arguments | Script property | Description |
---|---|---|---|
Raised when a control's value is about to be changed. | |||
Raised when a control's value has changed. | |||
Raised when the control's value is validating. | |||
Raised when the control's input is invalid. | |||
Raised when the validation state of the control changes. | |||
- | Raised just after the control has finished loading and is ready for interaction. |