This is a migrated thread and some comments may be shown as answers.

Cannot use MaxLength and MaskType together

6 Answers 706 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Kerry
Top achievements
Rank 1
Kerry asked on 02 May 2012, 05:52 PM
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

6 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 03 May 2012, 10:34 AM
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
0
Peter
Telerik team
answered on 07 May 2012, 01:32 PM
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 >>
0
mudzakkir
Top achievements
Rank 1
answered on 16 Apr 2015, 03:55 AM

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

0
mudzakkir
Top achievements
Rank 1
answered on 16 Apr 2015, 04:07 AM
please help me..
0
Kerry
Top achievements
Rank 1
answered on 16 Apr 2015, 05:15 AM

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

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Apr 2015, 10:45 AM
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.

 
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
commented on 21 Jul 2022, 12:24 PM

I know this is an old ticket, but this the closest I could find to what I am having an issue with.  We are using RadMaskEditBox with Mask Type of "EMAIL".  However, we need to limit the number of characters that can be entered, (due to database field size limitation).   From what I am reading, this is not possible for this control.  Is that the case, even after 7 years of updates?  We are running the latest Tekerik for UI WinForms.   Right now, we are using validation to let the user know they can not exceed a specified length, but I thought this control would work similar to the standard RadTextBoxControl.   

 

TIA

Dess | Tech Support Engineer, Principal
Telerik team
commented on 21 Jul 2022, 01:32 PM

Hello,   

RadMaskedEditBox internally hosts the standard MS TextBox. Hence, if you want to limit the number of entered characters, feel free to specify the MaskedEditBoxElement.TextBoxItem.MaxLength  property: 
            this.radMaskedEditBox1.MaskType = MaskType.EMail;
            this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.MaxLength = 7;
Thus, the user will be blocked while typing and the limit is reached.

I hope this information helps.
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
commented on 21 Jul 2022, 01:56 PM

Yea, I tried that, the MaxLength in the MaskedEditBoxElement.TextBoxItem doesn't seemed to be looked at.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 21 Jul 2022, 02:01 PM

I have attached my sample project for your reference which result with the latest version is demonstrated in the gif file. Please give it a try and see how it works on your end. Let me know what is the observed result.
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
commented on 21 Jul 2022, 02:28 PM

thank you so much.  I was trying to set the value though the UI Element editor, but if I coded as your example, that works great.   
Tags
MaskedEditBox
Asked by
Kerry
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Peter
Telerik team
mudzakkir
Top achievements
Rank 1
Kerry
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or