Click here to Skip to main content
14,980,680 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

   
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[^]
   
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!
sariqkhan 29-Sep-12 10:45am
   
bro i am a learner can you simply my work more. Its too difficult to understand "how to use regEX"
fjdiewornncalwe 29-Sep-12 12:19pm
   
The links I provided are couple of the simpler tutorials to using regex. I realize that you are a learner and that is why I added those links.
sariqkhan 29-Sep-12 12:55pm
   
awsome but this link help me to know what is regex especially
http://www.codeproject.com/Articles/13255/Validation-with-Regular-Expressions-Made-Simple
Espen Harlinn 29-Sep-12 12:26pm
   
5'ed!

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