RadMaskedTextInput represents a control for entering string values like phone numbers, IBAN, post codes, product codes etc. User can limit the user input or set literal/escaped symbols in the input via the Mask property. When the Mask is an empty string, the control behaves like a normal TextBox (free form text input).
Its Value property is of type string and it also exposes the ValueFormat property which allows you to alter the resulting value by including prompt and/or literal characters.
Example 1: Adding a RadMaskedTextInput in XAML
<input:RadMaskedTextInput Mask="(###) ###-####" ValueFormat="IncludePromptAndLiterals" />
RadMaskedTextInput allows you to set the behavior of the Value property in a mask scenario (when the Mask property is set).
By default the Value holds the characters without including the prompt characters and the literals defined in the mask. You can alter this and allow the value to hold also literals and prompt characters by setting the ValueFormat property of the control. The property is an enumeration of type ValueFormat which contains several options described in the next sections.
Example 2: Setting the value mode
This is the default mode and it tells the masked input to store the value without any prompt characters or literals given in the mask. For example, if the Mask is set to "##-##" and you enter "22-22", the Value property will contain "2222". The opposite scenario also applies - if you set the Value property to "2222" the control will display "22-22". If you set the Value to "222" the displayed value will be "22-2_", where the '_' character is the default placeholder.
The displayed text can be obtained via the Text property of RadMaskedTextInput.
When this mode is enabled the Value property of the masked input control will contain also the literals defined in the Mask property. For example if the Mask is set to "##-##" and you enter "22-22" the Value property will contain the value "22-22", where the '-' character is the literal from the mask. If you set the Value to "22-2", the displayed text will be "22-2_", where the '_' character is the default placeholder.
Note that if you set a Value that doesn't include literals, the control will automatically, parse it according to the applied Mask and then update the Value property. For example setting the Value to "222" will display "22-2_" and then the Value will be updated to "22-2".
When this mode is enabled the Value property of the masked input control will contain also the prompt characters for the missing positions required by the Mask property. For example if the Mask is set to "####" and you enter "222" the Value property will be "222_", where the '_' character is the default placeholder.
When this mode is enabled the Value property of the masked input control will contain also the literals and prompt characters for the missing positions required by the Mask property. For example if the Mask is set to "##-##" and you enter "222" the Value property will be "22-2_".
You can take advantage of the 'no-mask' functionality of the RadMaskedTextInput control by setting its Mask property to an empty string.
Example 4: Adding a RadMaskedTextInput in XAML
<input:RadMaskedTextInput Mask="" />
Allow Only Completed Values
The RadMaskedInput control will update its Value property only when its input passes the validation process. The validation rules are determined by the symbols set in the Mask property. Otherwise, the ValueChanged event won't be triggered. To allow property change on every user input, you can set the AllowOnlyCompletedValues property to False.
Example 5: Allow Only Completed Values
<telerik:RadMaskedTextInput Mask="AAAAAA" AllowOnlyCompletedValues="False" />
Restrict to ASCII
The RestrictToAscii property allows you to restrict input to ASCII-compatible characters if you do not wish to allow the entire Unicode set.
The RadMaskedTextInput also exposes a read-only IsMaskCompleted property which you can use to display some information to the end-user whether all required inputs have been entered into the formatted string.