RadControls for Silverlight

The purpose of this tutorial is to show you how to use No mask with RadMaskedTextBox. The NoneMaskType is used in the following cases:

  • When you want to use a TextBox with Telerik styles applied.
  • When you need a Watermark TextBox.
  • When you need a simple regExp support.
  • When you want to switch On/Off the filtering logic of the TextBox at runtime.

Setting No Mask

In order to use None Mask type in RadMaskedTextBox, you need to set the RadMaskedTextBox's MaskType property to None.

CopyXAML
<telerik:RadMaskedTextBox MaskType="None" />

Watermark TextBox

One possible usage of the NoneMaskType is in the cases when you need a Watermark TextBox. In this scenario, you should set the RadMaskedTextBox's MaskType property to None, and specify the EmptyContent property.

CopyXAML
<telerik:RadMaskedTextBox EmptyContent="This is watermark textbox" MaskType="None" />

Regular Expression Support

This section will show you how to use a regular expression with None MaskType to display only digits. The idea is pretty simple. You need to attach to the ValueChanging event and to perform the validation in the event handler.

CopyXAML
<telerik:RadMaskedTextBox EmptyContent="Enter digits only" 
                          MaskType="None"
                          ValueChanging="RadMaskedTextBox_ValueChanging" />
CopyC#
private void RadMaskedTextBox_ValueChanging( object sender, Telerik.Windows.Controls.RadMaskedTextBoxValueChangingEventArgs e )
{
    string newValue = e.NewMaskedText;
    Regex pattern = new Regex( @"^[\d]{0,}$" );
    e.Handled = pattern.IsMatch( newValue ) == false;
}
CopyVB.NET
Private Sub RadMaskedTextBox_ValueChanging(sender As Object, e As Telerik.Windows.Controls.RadMaskedTextBoxValueChangingEventArgs)
 Dim newValue As String = e.NewMaskedText
 Dim pattern As New Regex("^[\d]{0,}$")
 e.Handled = Not pattern.IsMatch(newValue)
End Sub
Tip
You can see a live demo demonstrating the usage of the NoMask feature here.

See Also