RadMaskedEditBox Numeric with Decimals...Need Help.

1 Answer 115 Views
MaskedEditBox
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Mark asked on 25 Jul 2023, 03:45 PM

I am using the RadMaskedEditBox to limit the user input. I need to allow the user to enter values from 0.0 to 999.9.  I was using a MaskType of Standard with a Mask of 999.9 or ###.#...however, this is forcing the user to enter numbers that are < 100 as 099.0. The users down't want to enter 0 for any value below 100, this is a real pain for them. so, I switched it to using a MaskType of Numeric and setting the Mask to N1, but this has its own problem of allowing the user to enter 9999999.9, which when saved, thows an error (the underline field is only 5 characters).  Since there is no MaxLenth field on this control, I need a better method.   I looked at using REGEX as the masktype, but, to this date, I still struggle with REGEX EXPRESSIONS and how to create an REGEX Expression to make this work.  Anyone help me out here. 

 

Thanks.

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 28 Jul 2023, 08:30 AM

Hello Mark,

There is no particular way to limit the value. Still, there are a few options which you could consider.

  • You can change the MaskType to Standart. Then you can change the Mask property using the standard characters. For example, you can set the Mask property to 099. This way the user can enter only one digit and the value will be in the range from 1 to 999. However, you have double numbers. Check the next approach.
  • You could consider using Regex. This approach will require manually creating a Regex expression that will accept digits only and have a range. However, this approach will require extra work in creating the expressions to match specific double numbers range.
  • You could consider using Validation. If you subscribe for example, to the Validating event you can check the value and Cancel the event. This way the user can't move to another control until it enters a valid value. You can also use Validation Provider to notify the user with a message why the value is invalid.

I think that the regex or validation provider will work for you. For the regex, I have prepared a sample one for you that matches numbers between 100 and 999.9. It may match some other combination, but I think you can use it as a starting point. You could limit the input key, for example, not allowing letters.

this.radMaskedEditBox2.Mask = "\\b(?:[1-9]\\d{2}(?:\\.\\d)?|999\\.9)\\b";
this.radMaskedEditBox2.MaskType = Telerik.WinControls.UI.MaskType.Regex;

When you enter your number and move the focus to another control, the validation will be triggered and a red mark will appear on the right showing that the value is not valid.

Another approach as I mentioned is to use the Validation Provider

I hope that one of these approaches will work for you.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 28 Jul 2023, 10:54 AM

Thanks for the response, decided to use spineditor instead, which gave us the desired functionality we needed.
Tags
MaskedEditBox
Asked by
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or