Cannot use MaxLength and MaskType together

7 posts, 1 answers
  1. Kerry
    Kerry avatar
    61 posts
    Member since:
    Nov 2008

    Posted 02 May 2012 Link to this post

    Hello,

    I am using Telerik Winform RadMaskedEditBox 2011.3.11.1116.  When using a MaskType "Numeric" and MaxLenght property set to 9 the MaxLenght does not work, it allows me to type more than 9 digits.  I have a need to ensure only numerics are entered but at the same time limit that value to a max of 999999.99.  I don't want the control filled with 00000000 when the position is not in use.

    Doesn't seem you can use the two properties together.

    Any ideas,

    Regards,

    Kerry
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 03 May 2012 Link to this post

    Hi Kerry, 

    This is by design as far as I'm aware. In order to add a mask for only numeric digits (and only a certain number of them) you could do the following: 

    this.radMaskedEditBox1.MaskType = MaskType.Standard;
    this.radMaskedEditBox1.Mask = "0000";

    This would ensure that the user can only type in 4 numeric digits. 

    The documentation for the mask editor can be found here and the subsections detail the types of masks and how to use them. 

    Hope this helps, but let me know if you need further assistance
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 07 May 2012 Link to this post

    Hi Kerry,

    Thank you for writing.

    The MaxLength property is valid only for MaskType None. For other types of masks (Numeric for example), the Mask property has higher priority than MaxLength. For example Numeric Mask type and "n3" Mask means unlimited digits before decimal separator and 3 digits after it, while g means unlimited numbers.

    Do not hesitate to contact us if you have other questions.

    Regards,
    Peter
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  5. mudzakkir
    mudzakkir avatar
    7 posts
    Member since:
    Oct 2014

    Posted 15 Apr 2015 Link to this post

    My mask type is regex... for site..

    I set maxLength to 250 (characters) but not working..

    I insert lorem ipsum text with more than 250 chars the maxlength property do not trim the text

  6. mudzakkir
    mudzakkir avatar
    7 posts
    Member since:
    Oct 2014

    Posted 15 Apr 2015 in reply to mudzakkir Link to this post

    please help me..
  7. Kerry
    Kerry avatar
    61 posts
    Member since:
    Nov 2008

    Posted 16 Apr 2015 in reply to mudzakkir Link to this post

    Its been a long time since I visited this however, I could not get both properties to work together, I opted to use MaxLength property which does not trim but stops the user from enter too many characters. I then used Javascript to validate that everything they entered was valid numeric with a RegEx

    function numericOnly(inputtxt)
    {
        var reg = new RegExp('^[0-9]+(\.[0-9]+)?$');
        if (reg.test(inputtxt))
            return true;
        else
            return false;
    }
     

    Hope this helps

  8. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 20 Apr 2015 Link to this post

    Hello,

    Thank you for writing.

    Since Q1 2013 SP1 (version 2013.1.321) the MaxLength property is removed. The Mask property should be used instead to set the appropriate mask value. You can refer to the following stackOverflow thread which demonstrates a sample approach how to use a Regular Expression to limit the allowed number of characters: http://stackoverflow.com/questions/1649435/regular-expression-to-limit-number-of-characters-to-10

    However, note that the user will be allowed to enter more symbols and when the RadMaskedEditBox is about to lose focus, it will try to validate its text and an error indicator will be displayed if the input does not match the Regex. You can specify the RadMaskedEditBox.MaskedEditBoxElement.TextBoxItem.MaxLength property in order to limit the user input.

    I hope this information helps. Should you have further questions, I would be glad to help.
     
    Regards,
    Dess
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready