RadMaskedTextBox empty value

4 posts, 0 answers
  1. Alexander
    Alexander avatar
    3 posts
    Member since:
    Sep 2011

    Posted 05 Dec 2011 Link to this post

    Hi,

    I have a masked text box with mask '<0..3><0..3><0..3>' which displays as '000' when empty. Is it possible to have an empty text box or one which displays '___' instead?

    For example:

    Empty: '___'
    Partially filled: '12_'
    Filled: '123' 


    Thanks
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Dec 2011 Link to this post

    Hello,

    Try setting Mask property as shown below.
    ASPX:
    <telerik:RadMaskedTextBox ID="msk" runat="server" Mask="(###)">
    </telerik:RadMaskedTextBox>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alexander
    Alexander avatar
    3 posts
    Member since:
    Sep 2011

    Posted 06 Dec 2011 Link to this post

    Hi Princy,

    that does work indeed as the '#' symbol is specified as:

    # DigitMaskPart Digit or space (optional). If this position is blank in the mask, it is rendered as a prompt character.

    the problem is that I want to limit the ranges of the digits and not allow any digit.

    Unfortunately setting the mask as '(<0..3><0..3><0..3>)' does not allow empty value also.

    Thanks

    Alexander
  5. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 06 Dec 2011 Link to this post

    Hi Alexander,

    You could use this workaround:
    <script type="text/javascript">
      function keyPress(sender, args)
      {
        if ((args.get_keyCharacter() > "3") && args.get_keyCharacter() <= "9")
          args.set_cancel(true);
      }
    </script>
    <telerik:RadMaskedTextBox ID="msk" runat="server" Mask="(###)">
      <ClientEvents OnKeyPress="keyPress" />
    </telerik:RadMaskedTextBox>

    Regards,
    Vasil
    the Telerik team
    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 RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top