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

MaskedEdit Email MaskType - How to detect invalid value in code

8 Answers 381 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Ali Mohamad
Top achievements
Rank 1
Ali Mohamad asked on 12 Aug 2011, 10:53 PM
Hi,

I am using the 2011.2.11.712 build of the WinForms controls.  When I set the RadMaskedEditBox MaskType to "Email", it works correctly and shows the icon when the value is invalid.

But, how do I detect in code that the validation failed? 

I have a form where the user enters an email address and I want to detect that the user entered an invalid value and not allow the save but rather show an error message.

Thanks

8 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Aug 2011, 03:09 PM
Hi Ali,

Thank you for writing.

Currently, you can determine whether the entered text is valid by manually checking it. Here is an example to change if the entered text is valid for the Email mask type:
void radMaskedEditBox1_Validating(object sender, CancelEventArgs e)
{
    bool valid = (radMaskedEditBox1.MaskedEditBoxElement.Provider as EMailMaskTextBoxProvider).Validate(radMaskedEditBox1.Text);
    if (!valid)
    {
        e.Cancel = true;
    }
}
We are currently working on improving this behavior in order to be more user friendly. 

I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.

Greetings,
Stefan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
RIZAL
Top achievements
Rank 1
answered on 02 Dec 2015, 02:25 AM

Hi, can you provide the code in vb?

Thank you.

0
Stefan
Telerik team
answered on 02 Dec 2015, 12:55 PM
Hello Mohd Rizal,

Here is the code in VB:
Private Sub radMaskedEditBox1_Validating(sender As Object, e As CancelEventArgs) Handles RadMaskedEditBox1.Validating
 
    Dim valid As Boolean = TryCast(radMaskedEditBox1.MaskedEditBoxElement.Provider, EMailMaskTextBoxProvider).Validate(radMaskedEditBox1.Text)
    If Not valid Then
        e.Cancel = True
    End If
End Sub

You can also use our online converter for conversion between C# and VB: http://converter.telerik.com/.

Regards,
Stefan
Telerik

0
RIZAL
Top achievements
Rank 1
answered on 08 Dec 2015, 04:16 AM
Thank you.
0
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
answered on 01 Sep 2020, 12:48 PM

This is pretty old, has a better solution been designed?   

 

I am using 2019.3.1022.40

 

Thanks

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Sep 2020, 12:33 PM

Hello, Mark,

Handling the Validating event is pretty straight-forward.

It is still the appropriate way for validating the input in RadMaskedEditBox.

Are you experiencing any difficulties with this approach?

Regards,
Dess | Tech Support Engineer, Sr.
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/.

0
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
answered on 03 Sep 2020, 02:10 PM

What I am looking for, is to see if RadMaskedEditBox data is valid, but I need to do this check in a button's click event.  I was hoping that the RadMaskedEditBox has a property or method that could be called, to see if validation passed or failed.  I could not find such method or property. I am a little confused by that, as there are visual cues to show if the RadMaskedEditBox text is not valid based on the mask type.

So, my solution was, in my button's click event, was to do something similar what Stefan posted back in 2011 and 2015. This seems to be working, but not as efficient as I think it can be done.  Also, I am not sure what improvements in behavior have happened since 2011, where Stefan mentioned that they were being worked on. I have seen no updates to this thread and the help documentation is very vague with how to us validation in this manner as well. 

 

Thanks

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Sep 2020, 11:08 AM

Hello, Mark,

As the Stefan's post described,  RadMaskedEditBoxElement offers the Validate method which expects some text to be validated as an input parameter. However, it doesn't return a boolean value indicating whether the input is valid or not. That is why it is convenient to use the Provider.Validate method as it is demonstrated below: 

bool isValid = this.radMaskedEditBox1.MaskedEditBoxElement.Provider.Validate(this.radMaskedEditBox1.Text);

Thus, you can determine whether the input is correct or not calling this method in a button's Click event handler.

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
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/.

Tags
MaskedEditBox
Asked by
Ali Mohamad
Top achievements
Rank 1
Answers by
Stefan
Telerik team
RIZAL
Top achievements
Rank 1
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or