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
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
;
}
}
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 >>
Hi, can you provide the code in vb?
Thank you.
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
This is pretty old, has a better solution been designed?
I am using 2019.3.1022.40
Thanks
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/.
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
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/.