MaskedEdit Email MaskType - How to detect invalid value in code

5 posts, 0 answers
  1. Ali Mohamad
    Ali Mohamad avatar
    15 posts
    Member since:
    Oct 2009

    Posted 12 Aug 2011 Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 16 Aug 2011 Link to this post

    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 >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. RIZAL
    RIZAL avatar
    11 posts
    Member since:
    Jun 2015

    Posted 01 Dec 2015 in reply to Stefan Link to this post

    Hi, can you provide the code in vb?

    Thank you.

  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 02 Dec 2015 Link to this post

    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

  6. RIZAL
    RIZAL avatar
    11 posts
    Member since:
    Jun 2015

    Posted 07 Dec 2015 in reply to Stefan Link to this post

    Thank you.
Back to Top
UI for WinForms is Visual Studio 2017 Ready