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

Using multiple patterns for RadMaskedEditBox using MaskType.Regex

4 Answers 328 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Danilo
Top achievements
Rank 1
Danilo asked on 24 Mar 2016, 11:16 AM

Hello

I'm trying to use a RadMaskedEditBox control with MaskType.Regex. And I want to be able to use more than 1 pattern for correct validating. I have those two patterns:

^[0-9]{6} [A-Z]{4} [0-9]{7}$
^[0-9]{5}$

I change those two patterns to one pattern like this:

^[0-9]{6} [A-Z]{4} [0-9]{7}$|^[0-9]{5}$

If I set the MaskType and Mask properties in designer, the control gets validated correct. But if I set those two properties programmatically (e.g. on form load), it is not validated correct. I can't type in five digits when setting the properties programmatically. Both patterns are exactly the same (also in debugger).

So I'm very confused now why it works in designer but not programmatically. I use this two lines of code in form load event:

radMaskedEditBox1.MaskType = MaskType.Regex;
radMaskedEditBox1.Mask = "^[0-9]{6} [A-Z]{4} [0-9]{7}$|^[0-9]{5}$";

The first pattern (before pipe character) can be validated, but not the second one. The second one can only be validated if I set the properties in designer.

Do you have any suggestions? Do I have to remember something?

Regards,
Danilo

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 24 Mar 2016, 03:11 PM
Hello Danilo,

Thank you for writing.

The only difference, in this case, is that the Mask is set before the MaskType at design time. Nevertheless, I have logged this issue in our Feedback Portal. You can track the item for status changes and add your vote for it here.

To workaround the issue you can set the Mask before setting the MaskType:
private void RadForm1_Load(object sender, EventArgs e)
{
    radMaskedEditBox1.Mask = "^[0-9]{6} [A-Z]{4} [0-9]{7}$|^[0-9]{5}$";
    radMaskedEditBox1.MaskType = MaskType.Regex;
}

Your Telerik Points have been updated for this report.

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Danilo
Top achievements
Rank 1
answered on 29 Mar 2016, 09:14 AM

Hello Dimitar

Thanks for the answer. This fixed my issue. I'll keep an eye on the feedback portal, thank you.

Regards,
Danilo

0
Gh Reza
Top achievements
Rank 1
answered on 05 Apr 2020, 05:38 PM

Hi Dear !

I want using GridViewMaskBoxColumn in following example :

  GridViewMaskBoxColumn maskBoxColumn = new GridViewMaskBoxColumn();
            maskBoxColumn.Name = "PostalCode";
            maskBoxColumn.FieldName = "PostalCode";
            maskBoxColumn.HeaderText = "Postal Code";
            maskBoxColumn.MaskType = MaskType.Regex;
            maskBoxColumn.Mask = @"^[1-9]\d{4}-[1-9]\d{4}$";

I have a problem with this at runtime :

1- I don't see any mask in my column. an user can input any format of string.

thank you

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Apr 2020, 04:35 AM

Hello, Reza,

The following help article gives more details about the different mask characters that RadMaskedEditBox offers and specifically the MaskType.Regex: https://docs.telerik.com/devtools/winforms/controls/editors/maskededitbox/mask-types-and-providers 

https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions 

In addition, regular expressions are usually tricky to pick up the proper expression that you need. That is why I would recommend you to test the potential regular expression  before using it. There are quite a lot of online RegEx testers that may be suitable for you: https://www.regextester.com/ 

If you are experiencing any further problems, feel free to submit a support ticket from your Telerik account and provide a sample project replicating the undesired behavior. Thus, our support engineers would gladly assist you.

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
MaskedEditBox
Asked by
Danilo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Danilo
Top achievements
Rank 1
Gh Reza
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or