Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I just want to know the code of that will return false like the below code. When value in textbox will be space. And also only alphabets and numbers are allowed neither it will return false. Can i do this in windows form like which i had said? Is there any kind of stuff

C#
private bool ValidateNumbers()
        {
            if (textBox2.Text == string.Empty)
            {
                return true;
            }
            char[] testArr = textBox2.Text.ToArray();
            bool stat = false;
            for (int i = 0; i < testArr.Length; i++)
            {
                if (!char.IsNumber(testArr[i]))
                {
                    stat = true;
                }
            }
            return stat;
        }


code is correct )
Posted
Updated 29-Sep-12 4:13am
v2

 
Share this answer
 
Comments
sariqkhan 29-Sep-12 10:31am    
i am using error provider. Can regEX be usefull with error provider? I am making methods which returns true or false. The by the output i use error provider. Can regex be helpfull for me?
Your better solution would be to use regular expressions. The regular expression based on your question would be "^[a-zA-Z0-9]*$".
Here is a regex tutorial: The 30 Minute Regex Tutorial[^]
How to use them in C#: Regular Expressions in dotNet[^]
 
Share this answer
 
Comments
sariqkhan 29-Sep-12 10:29am    
is this for windows form?
Maciej Los 29-Sep-12 10:33am    
Yes, it is, but not only for WinForms!
sariqkhan 29-Sep-12 10:31am    
i am using error provider. Can regEX be usefull with error provider? I am making methods which returns true or false. The by the output i use error provider. Can regex be helpfull for me?
Maciej Los 29-Sep-12 10:34am    
Yes, you can use it!
Maciej Los 29-Sep-12 10:32am    
Marcus, i agree with you ;) See my answer...
+5 of course!

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