RadmaskedEditBox should not allow you to type hyphens (or other special characters).

1 Answer 71 Views
MaskedEditBox
Giri
Top achievements
Rank 1
Iron
Giri asked on 17 May 2022, 11:32 AM
Hello Team,

In our application, we are using RadMaskedEditbox for the Phone and Fax values.

We are using the property for MaskType is Standard & Mask is (###) ###-#### & & & & & & & &

Here we need to allow only the numeric value, not special characters. (Do not allow them to enter the hyphen.)

The problem is: https://prnt.sc/xsW5oONnZLN4

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 May 2022, 02:41 PM
Hello, Giri,   

Please refer to the following article which lists all available mask characters when using the Standard mask:
https://docs.telerik.com/devtools/winforms/controls/editors/maskededitbox/standard-masks 

If you want to restrict some of the character, you can use the following custom StandartMaskTextBoxProvider
        public RadForm1()
        {
            InitializeComponent();

            this.radMaskedEditBox1.MaskType = MaskType.Standard;
            this.radMaskedEditBox1.Mask ="(###) ###-#### & & & & & & & &";
            this.radMaskedEditBox1.MaskedEditBoxElement.Provider = new CustomStandartMaskTextBoxProvider(this.radMaskedEditBox1.Mask,
                this.radMaskedEditBox1.Culture, 
                this.radMaskedEditBox1.MaskedEditBoxElement, false, '_', '*', true);  
        }
         

        public class CustomStandartMaskTextBoxProvider : StandartMaskTextBoxProvider
        { 
            public CustomStandartMaskTextBoxProvider(string mask, CultureInfo culture, RadMaskedEditBoxElement owner,
                bool allowPromptAsInput, char promptChar, char passwordChar, bool restrictToAscii) : 
                base(mask, culture, owner, allowPromptAsInput, promptChar, passwordChar, restrictToAscii)
            {
            }
            public override void KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar=='-')
                {
                    e.Handled = true;
                    return;
                }
                base.KeyPress(sender, e);
            } 
        }
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Giri
Top achievements
Rank 1
Iron
commented on 19 May 2022, 08:10 AM

Hello Dess,

Thanks for the timely help. The code works correctly. Thanks a bunch.

Tags
MaskedEditBox
Asked by
Giri
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or