RadMaskedTextBox remove empty spaces on display

3 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 09 Feb 2014 Link to this post

    Since I have variable widht numbers in my masked textbox I would like to remove the empty spaces when the textbox loses focus (on display).
    So for example something that on focus appears like +39__-12__-1234____ should appear like +39-12-1234 when the box loose focus and not like +39  -12  -1234
    Also it seems that pressing the "del" key leaves empty spaces. In a mask like ####-#### it doesn't make much sens to have 12 4-1 34 with spaces in the middle.
    Of course when you retrieve the values all this is fixed but preventing it in the input and a correct display on blur would be nice. 
  2. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 09 Feb 2014 in reply to Massimiliano Link to this post

    I forgot to say I tryed a solution for the first issue (not for the prevention of empty spaces during input but for the removal on display) but it doesn't seem to work as expected:

                    <telerik:RadMaskedTextBox ID="maskedOfficePhone" runat="server" CssClass="span3" Mask="+####-####-########"
                                              Rows="1" DisplayFormatPosition="Right" DisplayPromptChar=""
                                              PromptChar="_" EmptyMessage="Mobile phone" InvalidStyleDuration="150" AllowEmptyEnumerations="false" ClientEvents-OnBlur="stripmask"
                                              AutoCompleteType="Cellular" Text="+39-12-258" ResetCaretOnFocus="false" SelectionOnFocus="CaretToBeginning" NumericRangeAlign="Right">
    <telerik:RadScriptBlock runat="server">
        <script type="text/javascript">
            function stripmask(sender, eventArgs) {
                sender.set_value(sender.get_valueWithLiterals().replace(' ',''));
  3. Viktor Tachev
    Viktor Tachev avatar
    1786 posts

    Posted 12 Feb 2014 Link to this post

    Hi Massimiliano,

    When a Mask is set for the RadmaskedTextBox  the input expects the number of characters that are set in the mask. If less characters are entered the PromptChar symbol is displayed in the empty places.

    If you need ho handle a situation where phone numbers with various length will be entered you could use two RadNumericTextBox controls - one for the area code and one for the number.

    Viktor Tachev
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top