none
Windows Form validation using error provider

    Question

  • Hi All,

    I need to validate my windows form using Errorprovider.
    i have four textbox in my form
    name, phonenumber, salary,emailId
    1)All four textbox is not accept empty data.
    2)name textbox accept only alphabets and name length should not less then 3 character.
    3)phonenumber should accept only integer value and, not accept negative value and length should be 10 digit.
    4)salary only accept integer, not accept negative value.
    5)email id is a specific format.

    can someone explain me.

    Thanks & Regards,
    Jyotsna

    Wednesday, January 25, 2017 8:24 AM

All replies

  • Hi Jyotsna,

    Welcome to the MSDN forum.

    Refer to your description, you can have a look at this How to: Display Error Icons for Form Validation with the Windows Forms ErrorProvider Component

    There has the example code for C#/C++/VB and you can the method textBox1_Validating to check if the text of textbox is match your requirement or not.

    For the detail judgment condition of each textbox, you need to use the regular expression to achieve your requirement like the following:

    Name: ^[a-zA-Z]{1,3}$

    Email: \w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}

    For code: if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "^[a-zA-Z]{1,3}$")) then display the error message.

    For the rule of the other textboxes, you can search the information about the regular expression per your detail requirement and develop language, there should have some useful information that helpful for your question.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, January 26, 2017 6:41 AM
    Moderator
  • Hi Sara,

    Thanks for explain me.

    My another question is, in my form one groupbox is there, and it contain 2 radio button Male and female,

    i need to validate using error provider in c# windows application.

    my requirement is restrict user if they not select any radio button.

    and error provider message should be display like, please select your gender.

    Please Explain me.

    Thanks & Regards,

    Jyotsna


    Friday, January 27, 2017 8:40 AM
  • Hi Jyotsna,

    Thank you for your update.

    Usually, we discuss one question in one thread. For your another question in C# windows application, I recommend you redirect to the C# language support forum: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral
    and create a new thread for a more professional support, since
    our forum is to discuss Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor.

    BTW, if you think my reply is helpful, you can mark it as answer, that will help other community members who meet the same or similar issue to search this information, thank you for your understanding.


    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, January 30, 2017 1:59 AM
    Moderator