MaskedTextBox Blazor API

MaskedTextBox Properties

NameTypeDefaultDescription
AllowPromptAsInputboolfalseChecks if the specified promptChar character is recognized as a valid input, allowing the user to enter it into the field. If promptChar is considered valid, it will be accepted and processed as part of the user’s input; otherwise, it will be rejected.
AsciiOnlyboolfalseSpecifies whether the input field restricts user entries to characters within the standard ASCII character set (codes 0–127), excluding all non-ASCII symbols, accented letters, and characters from other languages.
AutoFocusboolfalseDetermines if the input element automatically receives focus when the page loads, allowing users to begin typing immediately without manually selecting the field.
AutoShowMaskboolfalseControls whether the input mask is displayed or hidden when the input field receives or loses focus, regardless of whether a placeholder is specified. This setting applies even if no placeholder attribute is present on the input element.
CutCopyMaskFormatMaskedTextBoxCutCopyMaskFormatMaskedTextBoxCutCopyMaskFormat.ExcludePromptAndLiteralsSpecifies whether formatting characters (such as literals and prompt symbols) included in an input mask are also copied to the clipboard when performing cut or copy operations. If enabled, both the user's input and the input mask characters will be included in the clipboard data; if disabled, only the user's input is copied.
DisabledboolfalseDetermines whether the element is interactive or inactive. When enabled, users can interact with the element; when disabled, the element appears dimmed and does not respond to user input.
EnterKeyBehaviorEnterKeyBehaviorEnterKeyBehavior.SubmitDefines the action performed when the "Enter" key is pressed. Possible values include "submit" (submits the form), "newline" (inserts a new line), or "none" (no action). The default value is "submit".
HidePromptOnLeaveboolfalseControls whether the prompt character in the input mask is hidden when the masked text box loses focus. When set to true, the prompt character will not be visible in the textbox after it loses focus; when set to false, the prompt character remains visible even when the textbox is not focused. This helps manage what users see when interacting with the masked input field.
Hintstring""Displays supplementary helper text beneath the element. This hint appears exclusively when the element is focused, providing contextual guidance to the user during input or interaction. The helper text is hidden when the element is not focused, ensuring a clean interface when not needed.
IsOverwriteModeboolfalseSpecifies whether new user input will replace the current input value entirely, or if it will be appended to or combined with the existing value. When enabled, any new input overwrites the existing content; when disabled, new input is added to the existing value without removing it.
Labelstring""Displays a label positioned above the element. The label remains constantly visible, providing clear identification for the associated element at all times.
UnlockKeystring""Defines or retrieves the unlockKey, a unique identifier or code required to activate and access the product's full features.
Localestring"en"Specifies or retrieves the current language setting for the application or component. This property determines which set of localized messages from the messages object will be used for display, enabling support for multiple languages. When you set the language, the corresponding message translations from the messages property are applied automatically.
Maskstring"#####"Specifies the input mask pattern that determines the allowed format and structure of user input. This ensures that the entered data matches the required criteria, such as a phone number, date, or custom format.
MaskCompletedboolfalseSpecifies whether every required field defined by the mask has been filled in with valid data. Returns true if all required fields are populated; otherwise, returns false.
MaskFullboolfalseSpecifies whether every required and optional field defined by the mask has been filled with a value. If true, all fields that the mask references are populated; if false, at least one referenced field remains unset.
MaxLengthint5Specifies the upper limit on the number of characters that a user is allowed to input. If the user attempts to enter more characters than this limit, additional input will be prevented or ignored. This property is commonly used in form fields to enforce data length constraints and ensure consistent data entry.
MessagesobjectN/ADefines or retrieves an object containing customizable text strings used within the widget, allowing for localization of user interface elements. This property works in conjunction with the locale property to provide translations and adapt the widget's display language to different regions or languages. Use this to specify or override default labels, messages, or prompts shown in the widget.
Namestring""Sets or retrieves the value of the element's name attribute. The name attribute identifies the element within an HTML form, ensuring its value is included in the form data sent to the server upon submission. This is essential for correctly processing user input on the backend.
Placeholderstring""Specifies the placeholder text displayed in the input field when both the value and mask properties are unset or empty. This text provides users with a hint or example of the expected input format until they enter a value.
PromptCharstring"_"Specifies the character used as the placeholder in the input mask for the element. This character indicates where user input is expected within the input field.
ReadonlyboolfalseWhen the element is set to readonly, users can view its content but cannot modify or interact with it in any way. This ensures that the element’s value remains unchanged by user input, while still being visible on the page.
RejectInputOnFirstFailureboolfalseSpecifies whether the parsing process should immediately halt upon encountering the first invalid character in the user input, or continue attempting to parse the remaining input.
RequiredboolfalseIndicates that this input field is required and cannot be left empty; users must provide a value before the form can be successfully submitted.
ResetOnPromptboolfalseControls whether entering a character in the input field that matches the prompt character will reset the currently selected value. This setting is relevant only when allowPromptAsInput is enabled, meaning the prompt character can be used as user input. When enabled, if the user types the prompt character, the input’s selected value will be cleared; otherwise, the value remains unchanged.
ResetOnSpaceboolfalseSpecifies whether pressing the spacebar will clear the currently selected value in the input field. When set to true, pressing the space key will reset (clear) the selection; when set to false, the value remains unchanged.
RightToLeftboolfalseSpecifies or retrieves a Boolean value that determines whether the element’s content is aligned to support right-to-left (RTL) languages, such as Arabic or Hebrew. When set to true, the element’s text direction and alignment are adjusted to display content appropriately for RTL locales.
SelectAllOnFocusboolfalseDetermines if the entire value of the input field will be automatically highlighted (selected) when the input receives focus, allowing users to easily replace or copy the existing content.
TextMaskFormatMaskedTextBoxTextMaskFormatMaskedTextBoxTextMaskFormat.ExcludePromptAndLiteralsSpecifies whether the value entered in the input field should include or exclude the static characters (prompts and literals) defined by the input mask. When enabled, the resulting value will contain these mask characters; otherwise, only the user input (without mask characters) will be stored.
Themestring""Specifies the visual theme to be applied. The theme controls the overall appearance—including colors, fonts, and style—of the element, ensuring a consistent and customizable look and feel.
UnfocusableboolfalseIf this property is set to true, the element will be excluded from keyboard navigation and cannot receive focus, either by tabbing or programmatically.
Valuestring""Gets the current value of the element or sets a new value for the element, depending on how the method is used. When called without arguments, it returns the element's current value. When provided with a value as an argument, it updates the element with the specified value. Commonly used with form input elements.
ValidationobjectN/A

A callback function that enables you to define custom validation logic for the input value. This function receives the input value as an argument and should return a boolean value: return true if the value is considered valid, or false if it is invalid. If the function returns false, the input will be treated as invalid and may trigger corresponding validation error messages or prevent form submission. Use this to implement validations that go beyond the default rules.

MaskedTextBox Methods

NameTypeArgumentsDescription
GetValueAsync()Task<string>'N/A'Gets the &quot;Value&quot; property as Task&lt;string&gt;.
Refreshvoid'N/A'Refreshes the Blazor Component. Performs a layout of the HTML Elements and recalculates the measurements.
Rendervoid'N/A'Re-renders the Blazor Component. This method will make a full re-render.
StateHasChangedvoid'N/A'Refreshes the state and Re-renders the Blazor Component, if necessary.

MaskedTextBox Events

NameTypeDescriptionEvent Detail
OnChangeEventCallback<Event>This event is triggered whenever the user modifies the content of the Text Box, such as by typing, deleting, or pasting text. It fires each time the value of the Text Box changes, allowing you to respond to user input in real-time.dynamic oldValue- The previous value before it was changed., dynamic value- The new value.
Changedevent MaskedTextBoxChangedEventHandlerThis event is triggered whenever the user modifies the content of the Text Box, such as by typing, deleting, or pasting text. It fires each time the value of the Text Box changes, allowing you to respond to user input in real-time.MaskedTextBoxChangedEventArgs
OnChangingEventCallback<Event>This event is triggered whenever a key is released (on key up) in the MaskedTextBox control and the input value has been modified as a result. It only fires if the key up event causes a change in the current value of the MaskedTextBox, allowing you to respond specifically to user edits in real-time.dynamic oldValue- The previous value before it was changed., dynamic value- The new value.
Changingevent MaskedTextBoxChangingEventHandlerThis event is triggered whenever a key is released (on key up) in the MaskedTextBox control and the input value has been modified as a result. It only fires if the key up event causes a change in the current value of the MaskedTextBox, allowing you to respond specifically to user edits in real-time.MaskedTextBoxChangingEventArgs
OnValidationEventCallback<Event>This event is triggered when the <b>validation</b> property is set. It indicates the result of the validation process—specifically, whether the validation completed successfully (<code>true</code>) or failed (<code>false</code>). Use this event to respond to changes in the validation state of the associated data or form.dynamic success- A flag inidicating whether the validation was successfull or not.
Validationedevent MaskedTextBoxValidationedEventHandlerThis event is triggered when the <b>validation</b> property is set. It indicates the result of the validation process—specifically, whether the validation completed successfully (<code>true</code>) or failed (<code>false</code>). Use this event to respond to changes in the validation state of the associated data or form.MaskedTextBoxValidationedEventArgs

Enums

MaskedTextBoxCutCopyMaskFormat

MaskedTextBoxCutCopyMaskFormat.ExcludePromptAndLiterals
MaskedTextBoxCutCopyMaskFormat.IncludePrompt
MaskedTextBoxCutCopyMaskFormat.IncludeLiterals
MaskedTextBoxCutCopyMaskFormat.IncludePromptAndLiterals

EnterKeyBehavior

EnterKeyBehavior.ClearOnSubmit
EnterKeyBehavior.Submit

MaskedTextBoxTextMaskFormat

MaskedTextBoxTextMaskFormat.ExcludePromptAndLiterals
MaskedTextBoxTextMaskFormat.IncludePrompt
MaskedTextBoxTextMaskFormat.IncludeLiterals
MaskedTextBoxTextMaskFormat.IncludePromptAndLiterals