validating

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

Page 1 of 1

6 Replies - 1162 Views - Last Post: 10 March 2008 - 12:04 PM Rate Topic: -----

#1 tumelo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-March 08

validating

Post icon  Posted 10 March 2008 - 04:28 AM

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,"");
			}	   
	   
		}


Is This A Good Question/Topic? 0
  • +

Replies To: validating

#2 tumelo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-March 08

Re: validating

Post icon  Posted 10 March 2008 - 04:36 AM

//here is my 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,"");
            }       
       
        }



Please use code tags when posting your code, like :code: :)

This post has been edited by PsychoCoder: 10 March 2008 - 06:01 AM

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: validating

Posted 10 March 2008 - 06:03 AM

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?
Was This Post Helpful? 0
  • +
  • -

#4 Nykc   User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 740
  • View blog
  • Posts: 8,654
  • Joined: 14-September 07

Re: validating

Posted 10 March 2008 - 06:58 AM

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:
Was This Post Helpful? 0
  • +
  • -

#5 thehat   User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: validating

Posted 10 March 2008 - 07:27 AM

Shouldn't that if have an OR rather than AND?

 if (num < 1 || num > 40)


Was This Post Helpful? 0
  • +
  • -

#6 WolfCoder   User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 828
  • View blog
  • Posts: 7,696
  • Joined: 05-May 05

Re: validating

Posted 10 March 2008 - 09:05 AM

Welcome to Dreamscode ^^

I would like to know more about yous for coming here~
Was This Post Helpful? 0
  • +
  • -

#7 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: validating

Posted 10 March 2008 - 12:04 PM

Topics merged. Please do not create duplicate topics.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1