Welcome to Dream.In.Code
Become a C# Expert!

Join 150,390 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,084 people online right now. Registration is fast and FREE... Join Now!




validating

 
Reply to this topicStart new topic

validating, i would like to know how to validate numbers between 1 and 40

tumelo
10 Mar, 2008 - 03:28 AM
Post #1

New D.I.C Head
*

Joined: 10 Mar, 2008
Posts: 1

CODE
private void button1_Click(object sender, EventArgs e)
        {
            //number btw 1 and 40 taken as a valid number.
            int num = int.Parse(textBox1.Text);

            if (num < 1 && num > 40)
            {
                errorProvider1.SetError(textBox1, "number not valid");
                textBox1.Focus();
                textBox1.SelectAll();              
            }

            else
            {
            errorProvider1.SetError(textBox1,"");
            }      
      
        }

User is offlineProfile CardPM
+Quote Post

tumelo
RE: Validating
10 Mar, 2008 - 03:36 AM
Post #2

New D.I.C Head
*

Joined: 10 Mar, 2008
Posts: 1

//here is my code.

csharp

private void button1_Click(object sender, EventArgs e)
{
//number btw 1 and 40 taken as a valid number.
int num = int.Parse(textBox1.Text);

if (num < 1 && num > 40)
{
errorProvider1.SetError(textBox1, "number not valid");
textBox1.Focus();
textBox1.SelectAll();
}

else
{
errorProvider1.SetError(textBox1,"");
}

}


Please use code tags when posting your code, like code.gif smile.gif

This post has been edited by PsychoCoder: 10 Mar, 2008 - 05:01 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Validating
10 Mar, 2008 - 05:03 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You are making things harder on yourself than they have to be, take a look into the RangeValidator Control, it will do your validating for you.

By the way, is the code you posted not working? Do you receive an error?
User is online!Profile CardPM
+Quote Post

Nykc
RE: Validating
10 Mar, 2008 - 05:58 AM
Post #4

That Just Happened!
Group Icon

Joined: 14 Sep, 2007
Posts: 4,509



Thanked: 18 times
Dream Kudos: 275
My Contributions
Hello Tumelo, welcome to Dream.In.Code! Since this forum is for introductions only it probably won't yield much of a result. Please post your question in the appropriate forum so someone can assist you.

Please use code.gif
User is online!Profile CardPM
+Quote Post

thehat
RE: Validating
10 Mar, 2008 - 06:27 AM
Post #5

D.I.C Head
Group Icon

Joined: 28 Feb, 2008
Posts: 217


Dream Kudos: 100
My Contributions
Shouldn't that if have an OR rather than AND?

CODE

if (num < 1 || num > 40)

User is offlineProfile CardPM
+Quote Post

WolfCoder
RE: Validating
10 Mar, 2008 - 08:05 AM
Post #6

ギュウ~
Group Icon

Joined: 5 May, 2005
Posts: 3,724



Thanked: 8 times
Dream Kudos: 1450
My Contributions
Welcome to Dreamscode ^^

I would like to know more about yous for coming here~
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Validating
10 Mar, 2008 - 11:04 AM
Post #7

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,327



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Topics merged. Please do not create duplicate topics.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:38PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month