Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How can crate validation in windows application?
Posted
Comments
Prerak Patel 22-Sep-11 2:09am    
Windows application in ASP.Net?!

u can use control validating event with errorprovider
example
here i have given an example to validate a textbox which accepts only integer the validate message is displayed on error provider
her is the code

C#
private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                int a = int.Parse(textBox1.Text);
            }
            catch
            {
                errorProvider1.SetError(textBox1, "Enter numbers only");
            }
        }


so here i have written the code in textBox1_Validating event

Hope this may help u
 
Share this answer
 
You can simply create methods and call accordingly to validate controls in Windows applications.as in mobile number validation
C#
class Validations
    {
        public static bool phone(string no)
        {


            string pattern = @"^\d{10}$";
            //string data = "111111111111";
            if (Regex.IsMatch(no, pattern))
            {
                return false;
            }
            else
            {
                return true;
            }

        }
}

and on Leave event of text box you can call this method.

Various Regular Expressions are used for validations.
 
Share this answer
 
Using Regular Expressions..
Regex is the best method for valudation..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900