Using multiple patterns for RadMaskedEditBox using MaskType.Regex

3 posts, 1 answers
  1. Danilo
    Danilo avatar
    40 posts
    Member since:
    Sep 2012

    Posted 24 Mar Link to this post

    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

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 24 Mar Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Danilo
    Danilo avatar
    40 posts
    Member since:
    Sep 2012

    Posted 29 Mar in reply to Dimitar Link to this post

    Hello Dimitar

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

    Regards,
    Danilo

Back to Top