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,"");
}
}
validatingi 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
#1
validating
Posted 10 March 2008 - 04:28 AM
Replies To: validating
#2
Re: validating
Posted 10 March 2008 - 04:36 AM
//here is my code.
Please use code tags when posting your code, like
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
This post has been edited by PsychoCoder: 10 March 2008 - 06:01 AM
#3
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?
By the way, is the code you posted not working? Do you receive an error?
#4
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
Please use
#5
Re: validating
Posted 10 March 2008 - 07:27 AM
Shouldn't that if have an OR rather than AND?
if (num < 1 || num > 40)
#6
Re: validating
Posted 10 March 2008 - 09:05 AM
Welcome to Dreamscode 
I would like to know more about yous for coming here~
I would like to know more about yous for coming here~
#7
Re: validating
Posted 10 March 2008 - 12:04 PM
Topics merged. Please do not create duplicate topics.
Page 1 of 1

New Topic/Question
Reply



MultiQuote






|