RadMaskedTextBox behavior

Thread is closed for posting
2 posts, 0 answers
  1. Elias
    Elias avatar
    4 posts
    Member since:
    Oct 2010

    Posted 25 Jan 2011 Link to this post


    I am using the RadMaskedTextBox to display a mask for a Social Security Number field, but I would like to display the mask only when the textbox has the focus.  When the textbox has the focus the mask should be displayed, such as ___-__-____.  If the user enters a number of values, the mask should still be displayed along with the values entered such as 415-74-____. If the user does not enter any values or deletes these values, the mask should not be displayed. Is this possible using the RadMaskedTextBox? 

    This brings a couple of issues to mind:

    1. When the mask is constantly displayed in a field that is not required or doesn't need to be validated, the RadMaskedTextBox will send the mask characters to the database field.  The developer then needs to code for the mask as in:




    (SSN == "___-__-____")
        SSN =

    I don't feel as though this is proper.  Is there a way around this? Can the mask be displayed only when values exists?


  2. Veli
    Veli avatar
    2002 posts

    Posted 31 Jan 2011 Link to this post

    Hi Elias,

    RadMaskedTextBox does not return the literal (-) or prompt (_) characters in its Text property. Only the user-entered value is returned, stripped of any literals in the mask itself. I have attached a small test page to demonstrate. Enter some digits and click the button to have the label show the RadMaskedTextBox.Text property.

    Hiding the mask when the textbox is not focused is not supported. You can display a different mask when RadMaskedTextBox is blurred by setting the DisplayMask property, but you cannot remove the mask completely.

    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top